NAME
Template::Caribou::Files - Role to load templates from files
VERSION
version 1.0.0
SYNOPSIS
package MyTemplate;
use Template::Caribou;
with 'Template::Caribou::Files' => {
dirs => [ './my_templates/' ],
intro => [ 'use 5.10.0;' ],
};
1;
DESCRIPTION
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.
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:
./foo.bou
./bar.bou
then the templates foo.bou
and bar.bou
will be created.
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;
}
}
METHODS
all_template_dirs
Returns a list of all template directories loaded by the class (directories included by parent classes included).
file_intro
Returns the arrayref of the intro lines added to the .bou templates.
ROLE PARAMETERS
dirs
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/.
intro
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'; },
];
};
AUTHOR
Yanick Champoux <yanick@cpan.org>
COPYRIGHT AND LICENSE
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.