The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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::Mustache 

Standard hash constructor.

Parameters:

  • %args -- Initialization data.

Returns:

  • (Template::Mustache) -- A new instance.

partial
    partial($receiver, $name) # => String 

Reads a named partial off disk.

Parameters:

  • (String) $name -- The name of the partial to lookup.

Returns:

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) # => 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.

    Returns:

    • (String) -- The fully rendered template.

    render($tmpl) # => String 

    Renders 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) # => 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.

    Parameters:

    • (Hash, Object) $data -- Data to be interpolated into the template.

    Returns:

    • (String) -- The fully rendered template.

    render($tmpl, $data) # => String 

    Renders 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) # => 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.

    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) # => String 

    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.

    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) # => String 

    Renders 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) # => String 

Reads the template off disk.

Returns:

template_extension
    template_extension # => String 

File extension for templates and partials.

Returns:

  • (String) -- $Template::Mustache::template_extension (defaults to 'mustache').

template_file
    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 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 # => 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.

   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:

  • (String) -- The empty string.

template_path
    template_path # => String 

Filesystem path for template and partial lookups.

Returns:

  • (String) -- $Template::Mustache::template_path (defaults to '.').

AUTHOR

Pieter van de Bruggen