Template::Provider::PrefixDBIC - A template provider that uses DBIC for database access and exhibits fallback functionality
version 0.01
use MySchema; use Template; use Template::Provider::PrefixDBIC; my $schema = MySchema->connect(...); my $provider = Template::Provider::PrefixDBIC->new( RESULTSET => $schema->resultset(...), PREFIXES => ['foo', 'default'], ); my $template = Template->new({ LOAD_TEMPLATES => [ $provider, ], }); $template->process('my_template'); # tries prefix = 'foo', name = 'my_template', then # prefix = 'default', name ='my_template'
Template::Provider::PrefixDBIC combines the fallback functionality of Template::Provider along with the database access of Template::Provider::DBIC.
If you don't need the fallback functionality, I highly recommend the Template::Provider::DBIC module.
Because it makes use of the full name of the template, we don't extract a table name from the template name, and the SCHEMA option to the constructor is thus unsupported, unlike in Template::Provider::DBIC.
In addition to the options provided by Template::Provider::DBIC (with the exception of SCHEMA), Template::Provider::PrefixDBIC also provides the following options:
The table column that contains the prefix for a template entry. This defaults to 'prefix'.
The list of prefixes that will be used to look up a template. If a string is provided, it is converted to a single-element array reference. Defaults to [''].
['']
When called with no arguments, this method returns the list of prefixes that will be used to look up a template. When called with a $new_prefixes argument, the internal list is replaced with $new_prefixes. $new_prefixes is automatically converted to an array reference if it isn't one.
$new_prefixes
If your prefix + name combination does not fall under a unique constraint in your database, this module could encounter multiple results for any given prefix/name combination. This module does no extra work to disambiguate; it will simply pick the first one that your database would return from the SELECT, whatever that might be.
Also, this provider implementation doesn't do any caching. I wrote this module because we need to invoke certain templates based on which customer is accessing a resource, and fallback to a default if there is no customer-specific behavior. I'd rather not let caching leak customer details; maybe I'll add it in a later release.
Template, Template::Provider, Template::Provider::DBIC
Rob Hoelz <rhoelz@inoc.com>
This software is copyright (c) 2011 by INOC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Template::Provider::PrefixDBIC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Provider::PrefixDBIC
CPAN shell
perl -MCPAN -e shell install Template::Provider::PrefixDBIC
For more information on module installation, please visit the detailed CPAN module installation guide.