Template::Mustache - Template::Mustache is an implementation of the fabulous Mustache templating language for Perl 5.8 and later
new($class, %args) # => Template::Mustache
Standard hash constructor.
Parameters:
%args -- Initialization data.
%args
Returns:
(Template::Mustache) -- A new instance.
partial($receiver, $name) # => String
Reads a named partial off disk.
(String) $name -- The name of the partial to lookup.
$name
(String) -- The contents of the partial (in template_path, of type template_extension), or the empty string, if the partial does not exist.
render # => String render($tmpl) # => String render($data) # => String render($tmpl, $data) # => String render($tmpl, $data, $partials) # => String render($tmpl, $data, $partials) # => String render($tmpl, $data, $partials) # => String
Overloads:
render # => String
Renders a class or instance's template with data from the receiver. The template will be retrieved by calling the template method. Partials will be fetched by partial.
(String) -- The fully rendered template.
render($tmpl) # => String
Renders the given template with data from the receiver. Partials will be fetched by partial.
(String) $tmpl -- The template to render.
$tmpl
render($data) # => String
(Hash, Object) $data -- Data to be interpolated into the template.
$data
render($tmpl, $data) # => String
Renders the given template with the given data. Partials will be fetched by partial.
(Hash, Class, Object) $data -- Data to be interpolated into the template.
render($tmpl, $data, $partials) # => String
Renders the given template with the given data. Partials will be looked up by calling the given code reference with the partial's name.
(Code) $partials -- A function used to lookup partials.
$partials
Renders the given template with the given data. Partials will be looked up by calling the partial's name as a method on the given class or object.
(Class, Object) $partials -- A thing that responds to partial names.
Renders the given template with the given data. Partials will be looked up in the given hash.
(Hash) $partials -- A hash containing partials.
template($receiver) # => String
Reads the template off disk.
(String) -- The contents of the template_file under template_path.
template_extension # => String
File extension for templates and partials.
(String) -- $Template::Mustache::template_extension (defaults to 'mustache').
$Template::Mustache::template_extension
template_file($receiver) # => String
The template filename to read. The filename follows standard Perl module lookup practices (e.g. My::Module becomes My/Module.pm) with the following differences:
Templates have the extension given by template_extension ('mustache' by default).
Templates will have template_namespace removed, if it appears at the beginning of the package name.
Template filename resolution will short circuit if $Template::Mustache::template_file is set.
$Template::Mustache::template_file
Template filename resolution may be overriden in subclasses.
Template files will be resolved against template_path, not $PERL5LIB.
$PERL5LIB
(String) -- The path to the template file, relative to template_path.
See Also:
template
template_namespace # => String
Package namespace to ignore during template lookups.
As an example, if you subclass Template::Mustache as the class My::Heavily::Namepaced::Views::SomeView, calls to render will automatically try to load the template ./My/Heavily/Namespaced/Views/SomeView.mustache under the template_path. Since views will very frequently all live in a common namespace, you can override this method in your subclass, and save yourself some headaches.
Template::Mustache
My::Heavily::Namepaced::Views::SomeView
./My/Heavily/Namespaced/Views/SomeView.mustache
Setting template_namespace to: yields template name: My::Heavily::Namespaced::Views => SomeView.mustache My::Heavily::Namespaced => Views/SomeView.mustache Heavily::Namespaced => My/Heavily/Namespaced/Views/SomeView.mustache
As noted by the last example, namespaces will only be removed from the beginning of the package name.
(String) -- The empty string.
template_path # => String
Filesystem path for template and partial lookups.
(String) -- $Template::Mustache::template_path (defaults to '.').
$Template::Mustache::template_path
Pieter van de Bruggen
To install Template::Mustache, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Mustache
CPAN shell
perl -MCPAN -e shell install Template::Mustache
For more information on module installation, please visit the detailed CPAN module installation guide.