Dancer::Template::TemplateSandbox - Template::Sandbox wrapper for Dancer
This class is an interface between Dancer's template engine abstraction layer and the Template::Sandbox module.
In order to use this engine, set the following setting:
template: template_sandbox
This can be done in your config.yml file or directly in your app code with the set keyword.
Note that Dancer configures the Template::Sandbox engine to use <% %> brackets instead of its default <: :> brackets, it also sets template_toolkit_compat to true.
You can pass additional options to the Template::Sandbox constructor from within the template_sandbox subsetting of the engines setting in your config.yml:
template_sandbox
engines
template: template_sandbox engines: template_sandbox: open_delimiter: <: close_delimiter: :>
You can enable and configure caching by setting the cache, cache_type and cache_dir settings.
cache
cache_type
cache_dir
cache may be one of 'cache_factory' or 'chi' to use Cache::CacheFactory or CHI respectively.
'cache_factory'
'chi'
cache_type will set the cache type, 'file' and 'memory' should both be fine, but other values may or may not work.
'file'
'memory'
cache_dir will need to be set if you set cache_type to 'file', but is otherwise ignored.
template: template_sandbox engines: template_sandbox: cache: cache_factory cache_type: file cache_dir: /var/tmp/cache/dancer template: template_sandbox engines: template_sandbox: cache: chi cache_type: memory
In keeping with Template::Sandbox philosophy, no template functions are enabled by default.
You can load them as class-wide template functions from your myapp.pm:
myapp.pm
package myapp; use Dancer; use Template::Sandbox qw/:function_sugar/; Template::Sandbox->register_template_function( localtime => ( no_args inconstant sub { scalar localtime() } ), );
Or you can use template function libraries with class-level imports:
package myapp; use Dancer; use Template::Sandbox; use Template::Sandbox::NumberFunctions qw/:all/;
The documentation in Template::Sandbox and Template::Sandbox::Library goes into more detail on both these scenarios.
Dancer, Template::Sandbox, Cache::CacheFactory, CHI
You can find documentation for this module with the perldoc command.
perldoc Dancer::Template::TemplateSandbox
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Template-TemplateSandbox
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Dancer-Template-TemplateSandbox
CPAN Ratings
http://cpanratings.perl.org/d/Dancer-Template-TemplateSandbox
Search CPAN
http://search.cpan.org/dist/Dancer-Template-TemplateSandbox
Sam Graham <libdancer-template-templatesandbox-perl BLAHBLAH illusori.co.uk>.
Based on work in Dancer::Template::TemplateToolkit by Alexis Sukrieh.
Copyright 2010 Sam Graham, all rights reserved. Portions derived from work copright Alexis Sukrieh.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Dancer::Template::TemplateSandbox, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Template::TemplateSandbox
CPAN shell
perl -MCPAN -e shell install Dancer::Template::TemplateSandbox
For more information on module installation, please visit the detailed CPAN module installation guide.