NAME
Template::Mustache - Template::Mustache is an implementation of the fabulous Mustache templating language for Perl 5.8 and later
METHODS
Class Methods
- new
-
new($class, %args) # => Template::MustacheStandard hash constructor.
Parameters:
%args-- Initialization data.
Returns:
(Template::Mustache) -- A new instance.
- partial
-
partial($receiver, $name) # => StringReads a named partial off disk.
Parameters:
(String)
$name-- The name of the partial to lookup.
Returns:
(String) -- The contents of the partial (in template_path, of type template_extension), or the empty string, if the partial does not exist.
- render
-
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) # => StringOverloads:
render # => StringRenders 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.
Returns:
(String) -- The fully rendered template.
render($tmpl) # => StringRenders the given template with data from the receiver. Partials will be fetched by partial.
Parameters:
(String)
$tmpl-- The template to render.
Returns:
(String) -- The fully rendered template.
render($data) # => StringRenders 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.
Parameters:
(Hash, Object)
$data-- Data to be interpolated into the template.
Returns:
(String) -- The fully rendered template.
render($tmpl, $data) # => StringRenders the given template with the given data. Partials will be fetched by partial.
Parameters:
(String)
$tmpl-- The template to render.(Hash, Class, Object)
$data-- Data to be interpolated into the template.
Returns:
(String) -- The fully rendered template.
render($tmpl, $data, $partials) # => StringRenders the given template with the given data. Partials will be looked up by calling the given code reference with the partial's name.
Parameters:
(String)
$tmpl-- The template to render.(Hash, Class, Object)
$data-- Data to be interpolated into the template.(Code)
$partials-- A function used to lookup partials.
Returns:
(String) -- The fully rendered template.
render($tmpl, $data, $partials) # => StringRenders 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.
Parameters:
(String)
$tmpl-- The template to render.(Hash, Class, Object)
$data-- Data to be interpolated into the template.(Class, Object)
$partials-- A thing that responds to partial names.
Returns:
(String) -- The fully rendered template.
render($tmpl, $data, $partials) # => StringRenders the given template with the given data. Partials will be looked up in the given hash.
Parameters:
(String)
$tmpl-- The template to render.(Hash, Class, Object)
$data-- Data to be interpolated into the template.(Hash)
$partials-- A hash containing partials.
Returns:
(String) -- The fully rendered template.
- template
-
template($receiver) # => StringReads the template off disk.
Returns:
(String) -- The contents of the template_file under template_path.
- template_extension
-
template_extension # => StringFile extension for templates and partials.
Returns:
(String) --
$Template::Mustache::template_extension(defaults to 'mustache').
- template_file
-
template_file($receiver) # => StringThe 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_fileis set.Template filename resolution may be overriden in subclasses.
Template files will be resolved against template_path, not
$PERL5LIB.
Returns:
(String) -- The path to the template file, relative to template_path.
See Also:
- template_namespace
-
template_namespace # => StringPackage namespace to ignore during template lookups.
As an example, if you subclass
Template::Mustacheas the classMy::Heavily::Namepaced::Views::SomeView, calls to render will automatically try to load the template./My/Heavily/Namespaced/Views/SomeView.mustacheunder 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.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.mustacheAs noted by the last example, namespaces will only be removed from the beginning of the package name.
Returns:
(String) -- The empty string.
- template_path
-
template_path # => StringFilesystem path for template and partial lookups.
Returns:
(String) --
$Template::Mustache::template_path(defaults to '.').
AUTHOR
Pieter van de Bruggen