DOKK / manpages / debian 10 / libtenjin-perl / Tenjin::Context.3pm.en
Tenjin::Context(3pm) User Contributed Perl Documentation Tenjin::Context(3pm)

Tenjin::Context - In charge of managing variables passed to Tenjin templates.

        # this module is used internally, but if you insist, it is
        # in charge of the context object:
        # in your templates (unnecessary, for illustration purposes):
        <title>[== $_context->{title} =]</title>
        # instead use:
        <title>[== $title =]</title>

This module is in charge of managing Perl variables that are passed to templates upon rendering for direct usage. The context object is simply a hash-ref of key-value pairs, which are made available for templates as "standalone variables" named for each key in the hash-ref.

This module is also in charge of the actual rendering of the templates, or more correctly, for evaluating the Perl code created from the templates, first integrating the context variables to them, and returning the rendered output.

Finally, this module makes the Tenjin utility methods of Tenjin::Util available natively inside templates. See Tenjin::Util for more info.

Constructs a new context object, which is basically a hash-ref of key-value pairs which are passed to templates as variables. If a $vars hash-ref is passed to the constructor, it will be augmented into the created object.

To illustrate the context object, suppose it looks like so:

        {
                scalar          => 'I am a scalar',
                arrayref        => [qw/I am an array/],
                hashref =>      { i => 'am', a => 'hash-ref' },
        }

Then the variables $scalar, $arrayref and $hashref will be available for direct usage inside your templates, and you can dereference the variables normally (i.e. @$arrayref and %$hashref).

This method receives a compiled template and actually performes the evaluation the renders it, then returning the rendered output. If Tenjin is configured to "use strict", the script will be "eval"ed under "use strict".

This method receives the script created when reading a template and wraps it in a subroutine, "eval"s it and returns the rendered output. This method is called when compiling the template.

_build_decl()

This method is in charge of making all the key-value pairs of the context object available to templates directly by the key names. This is simply done by traversing the key-value pairs of the context object and adding an assignment line between a scalar variable named as the key and its appropriate value.

These methods are defined in Tenjin::Util and used here so they are made available natively inside templates. See Tenjin::Util for more information.

Tenjin, Tenjin::Util, Tenjin::Template.

See Tenjin.

2016-05-17 perl v5.22.2