Template::Provider (3)
Leading comments
Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) Standard preamble: ========================================================================
NAME
Template::Provider - Provider module for loading/compiling templatesSYNOPSIS
$provider = Template::Provider->new(\%options); ($template, $error) = $provider->fetch($name);
DESCRIPTION
The Template::Provider is used to load, parse, compile and cache template documents. This object may be sub-classed to provide more specific facilities for loading, or otherwise providing access to templates.The Template::Context objects maintain a list of Template::Provider objects which are polled in turn (via fetch()) to return a requested template. Each may return a compiled template, raise an error, or decline to serve the request, giving subsequent providers a chance to do so.
The Template::Provider can also be subclassed to provide templates from a different source, e.g. a database. See
This documentation needs work.
PUBLIC METHODS
new(\%options)
Constructor method which instantiates and returns a new "Template::Provider" object. A reference to a hash array of configuration options may be passed.See ``
fetch($name)
Returns a compiled template for the name specified. If the template cannot be found then "(undef, STATUS_DECLINED)" is returned. If an error occurs (e.g. read error, parse error) then "($error, STATUS_ERROR)" is returned, where $error is the error message generated. If theload($name)
Loads a template without parsing or compiling it. This is used by the thestore($name, $template)
Stores the compiled template, $template, in the cache under the name, $name. Susbequent calls to "fetch($name)" will return this template in preference to any disk-based file.include_path(\@newpath)
Accessor method for the "INCLUDE_PATH" setting. If called with an argument, this method will replace the existing "INCLUDE_PATH" with the new value.paths()
This method generates a copy of the "INCLUDE_PATH" list. Any elements in the list which are dynamic generators (e.g. references to subroutines or objects implementing a "paths()" method) will be called and the list of directories returned merged into the output list.It is possible to provide a generator which returns itself, thus sending this method into an infinite loop. To detect and prevent this from happening, the $MAX_DIRS package variable, set to 64 by default, limits the maximum number of paths that can be added to, or generated for the output list. If this number is exceeded then the method will immediately return an error reporting as much.
CONFIGURATION OPTIONS
The following list summarises the configuration options that can be provided to the "Template::Provider" new() constructor. Please consult Template::Manual::Config for further details and examples of each configuration option in use.INCLUDE_PATH
The
# single path my $provider = Template::Provider->new({ INCLUDE_PATH => '/usr/local/templates', }); # multiple paths my $provider = Template::Provider->new({ INCLUDE_PATH => [ '/usr/local/templates', '/tmp/my/templates' ], });
ABSOLUTE
The
my $provider = Template::Provider->new({ ABSOLUTE => 1, });
RELATIVE
The
my $provider = Template::Provider->new({ RELATIVE => 1, });
DEFAULT
The
my $provider = Template::Provider->new({ DEFAULT => 'notfound.html', });
If a non-existant template is requested through the Template process() method, or by an "INCLUDE", "PROCESS" or "WRAPPER" directive, then the "DEFAULT" template will instead be processed, if defined. Note that the "DEFAULT" template is not used when templates are specified with absolute or relative filenames, or as a reference to a input file handle or text string.
ENCODING
The Template Toolkit will automatically decode Unicode templates that
have a Byte Order Marker (
my $provider = Template::Provider->new({ ENCODING => 'utf8', });
See Encode for further information.
CACHE_SIZE
The
my $provider = Template::Provider->new({ CACHE_SIZE => 64, # only cache 64 compiled templates });
STAT_TTL
The
my $provider = Template::Provider->new({ STAT_TTL => 60, # one minute });
COMPILE_EXT
The
my $provider = Template::Provider->new({ COMPILE_EXT => '.ttc', });
COMPILE_DIR
The
my $provider = Template::Provider->new({ COMPILE_DIR => '/tmp/ttc', });
TOLERANT
The PARSER
The
my $provider = Template::Provider->new({ PARSER => MyOrg::Template::Parser->new({ ... }), });
DEBUG
The
use Template::Constants qw( :debug ); my $template = Template->new({ DEBUG => DEBUG_PROVIDER, });
SUBCLASSING
The "Template::Provider" module can be subclassed to provide templates from a different source (e.g. a database). In most cases you'll just need to provide custom implementations of the "_template_modified()" and "_template_content()" methods. If your provider requires and custom initialisation then you'll also need to implement a new "_init()" method.Caching in memory and on disk will still be applied (if enabled) when overriding these methods.
_template_modified($path)
Returns a timestamp of the $path passed in by calling "stat()". This can be overridden, for example, to return a last modified value from a database. The value returned should be a timestamp value (as returned by "time()", although a sequence number should work as well._template_content($path)
This method returns the content of the template for all "INCLUDE", "PROCESS", and "INSERT" directives.When called in scalar context, the method returns the content of the template located at $path, or "undef" if $path is not found.
When called in list context it returns "($content, $error, $mtime)", where $content is the template content, $error is an error string (e.g. ""$path: File not found""), and $mtime is the template modification time.
AUTHOR
Andy Wardley <abw@wardley.org> <wardley.org>COPYRIGHT
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.