OpenInteract::Template::Provider - Retrieve templates for the Template Toolkit


OpenInteract documentation  | view source Contained in the OpenInteract distribution.

Index


NAME

Top

OpenInteract::Template::Provider - Retrieve templates for the Template Toolkit

SYNOPSIS

Top

 $Template::Config::CONTEXT = 'OpenInteract::Template::Context';
 my $template = Template->new(
                       COMPILE_DIR    => '/tmp/ttc',
                       COMPILE_EXT    => '.ttc',
                       LOAD_TEMPLATES => [ OpenInteract::Template::Provider->new ] );
 my ( $output );
 $template->process( 'package::template', \%params, \$output );

DESCRIPTION

Top

NOTE: As shown above, you need to use OpenInteract::Template::Context as a context for your templates since our naming scheme ('package::name') collides with the TT naming scheme for specifying a prefix before a template.

This package is a provider for the Template Toolkit while running under OpenInteract. Being a provider means that TT hands off any requests for templates to this class, which has OpenInteract-specific naming conventions (e.g., 'package::template') and knows how to find templates in the sitewide package template directory or the normal package template directory

METHODS

Top

All of the following are object methods and have as the first argument the object itself.

fetch( $text )

Overrides Template::Provider.

Uses $text to somehow retrieve a template. The actual work to retrieve a template is done in _load(), although this method ensures that the template name is 'safe' and creates a name we use to save the compiled template.

Returns a two-element list: the first is a compiled template, the second is an error message. (Of course, if there is no error the second item will be undefined.)

_load( $name, $content )

Loads the template content, returning a two-element list. The first item in the list is the TT hashref, the second is an error message.

We try three ways to retrieve a template, in this order:

1.

scalar reference: If the template is a scalar reference it does not need to be retrieved, so we just put $content in the TT hashref structure as the data to process and return it.

2.

glob reference: If the template is a glob reference we treat it as a filehandle and read all data from $content in the TT hashref structure as the data to process as return it.

3.

filesystem template: Templates can be stored in the filesystem. If a template does not use $package it can be found under $WEBSITE_DIR/template; if it does, it can be found under $WEBSITE_DIR/template/$package or $WEBSITE_DIR/pkg/$package-version/template, in that order.

_refresh( $cache_slot )

Called when we use $cache_slot for a template. This refreshes the time of the slot and brings it to the head of the LRU cache.

You can tune the expiration time of the cache by setting the key:

 {cache}{template}{expire}

in your server configuration file to the amount of time (in seconds) to keep an entry in the cache.

_validate_template_name( $full_template_name )

Ensures that $full_template_name does not have any tricky filesystem characters (e.g., '..') in it.

_get_anon_name( $text )

If we get an anonymous template to provide, we need to create a unique name for it so we can compile and cache it properly. This method returns a unique name based on $text.

BUGS

Top

None known.

TO DO

Top

Testing

Needs more testing in varied environments.

SEE ALSO

Top

Template

Template::Provider

Slashcode http://www.slashcode.com/

COPYRIGHT

Top

AUTHORS

Top

Chris Winters <chris@cwinters.com>

Robert McArthur <mcarthur@dstc.edu.au>

Authors of Slashcode http://www.slashcode.com/


OpenInteract documentation  | view source Contained in the OpenInteract distribution.