Template::Mustache - Drawing Mustaches on Perl for fun and profit
version 0.5.6
use Template::Mustache; print Template::Mustache->render( "Hello {{planet}}", {planet => "World!"}), "\n";
Template::Mustache is an implementation of the fabulous Mustache templating language for Perl 5.8 and later.
See http://mustache.github.com.
Constructs a new regular expression, to be used in the parsing of Mustache templates.
The tag opening delimiter.
The tag closing delimiter.
Returns a regular expression that will match tags with the specified delimiters.
Reads a file into a string, returning the empty string if the file does not exist.
The name of the file to read.
Returns the contents of the given filename, or the empty string.
Can be called in one of three forms:
Creates an AST from the given template.
The template to parse.
An array reference to the AST represented by the given template.
Creates an AST from the given template, with non-standard delimiters.
An array reference to the delimiter pair with which to begin parsing.
Returns an array reference to the AST represented by the given template.
Parses out a section tag from the given template.
The name of the section we're parsing.
The index of the first character of the section.
Returns an array reference to the raw text of the section (first element), and the index of the character immediately following the close section tag (last element).
Produces an expanded version of the template represented by the given parse tree.
The AST of a Mustache template.
A subroutine that looks up partials by name.
The context stack to perform key lookups against.
Returns the fully rendered template as a string.
Performs a lookup of a $field in a context stack.
$field
The field to look up.
The context stack.
Returns the context element and value for the given $field.
Standard hash constructor.
Initialization data.
Returns A new Template::Mustache instance.
Template::Mustache
Filesystem path for template and partial lookups.
Returns a string containing the template path (defaults to '.').
File extension for templates and partials.
Returns the file extension as a string (defaults to 'mustache').
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.
My::Heavily::Namepaced::Views::SomeView
render
./My/Heavily/Namespaced/Views/SomeView.mustache
template_path
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.
Returns the empty 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:
My::Module
My/Module.pm
Templates have the extension given by template_extension ('mustache' by default).
template_extension
Templates will have template_namespace removed, if it appears at the beginning of the package name.
template_namespace
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
Returns The path to the template file, relative to template_path as a string. See template.
Reads the template off disk.
Returns the contents of the template_file under template_path.
template_file
Reads a named partial off disk.
The name of the partial to lookup.
Returns the contents of the partial (in template_path of type template_extension), or the empty string, if the partial does not exist.
Render a class or instances data, in each case returning the fully rendered template as a string; can be called in one of the following forms:
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.
template
partial
Renders the given template with data from the receiver. Partials will be fetched by partial.
The template to render.
Data (as hash or object) to be interpolated into the template.
Renders the given template with the given data. Partials will be fetched by partial.
Data (as a hash, class, or object) to be interpolated into the template.
Renders the given template with the given data. Partials will be looked up by calling the given code reference with the partial's name.
A function used to lookup 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.
A thing (class or object) that responds to partial names.
Renders the given template with the given data. Partials will be looked up in the given hash.
A hash containing partials.
Pieter van de Bruggen <pvande@cpan.org>
Yanick Champoux <yanick@cpan.org>
Ricardo Signes <rjbs@cpan.org>
This software is copyright (c) 2011 by Pieter van de Bruggen.
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::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.