Template::Caribou::Files - Role to load templates from files
version 1.2.0
package MyTemplate; use Template::Caribou; with 'Template::Caribou::Files' => { dirs => [ './my_templates/' ], intro => [ 'use 5.10.0;' ], }; 1;
A Caribou class consuming the Template::Caribou::Files role will automatically import all template files (i.e., all files with a .bou extension) under the given directories.
Template::Caribou::Files
.bou
The names of the imported templates will be their path, relative to the imported directories, without their extension. To take the example in the "SYNOPSIS", if the content of my_templates/ is:
my_templates/
./foo.bou ./bar.bou
then the templates foo.bou and bar.bou will be created.
foo.bou
bar.bou
The template files themselves will be eval'ed in the context of the parent class/namespace, and must return a coderef. E.g.,
# file ./foo.bou # should be done in the class declaration, but # can be done here as well use Template::Caribou::Tags::HTML ':all'; # likewise, would be better if added to # as a Template::Caribou::Files's intro use experimental 'signatures'; sub ($self) { div { say 'this is foo'; $self->bar; } }
Returns a list of all template directories loaded by the class (directories included by parent classes included).
Returns the arrayref of the intro lines added to the .bou templates.
The array ref of directories to scan for templates.
If not provided, it defaults to the directory associated with the template class. For example, for
package MyTemplates::Foo; use Template::Caribou; with 'Template::Caribou::Files'; 1;
located at lib/MyTemplates/Foo.pm, the default directory will be lib/MyTemplates/Foo/.
Arrayref of lines to add at the beginning of all .bou templates.
package MyTemplates::Foo; use Template::Caribou; with 'Template::Caribou::Files' => { intro => [ q{ use 5.10.0; }, q{ use experimental 'signatures'; }, ]; };
Yanick Champoux <yanick@cpan.org>
This software is copyright (c) 2017 by Yanick Champoux.
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::Caribou, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Caribou
CPAN shell
perl -MCPAN -e shell install Template::Caribou
For more information on module installation, please visit the detailed CPAN module installation guide.