trusty (3) Tenjin::Context.3pm.gz

Provided by: libtenjin-perl_0.070001-1_all bug

NAME

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

VERSION

       version 0.070001

SYNOPSIS

               # 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>

DESCRIPTION

       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.

INTERNAL METHODS

   new( [\%vars] )
       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).

   evaluate( $script, $template_name )
       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".

   to_func( $script, [$filename] )
       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.

UTILITY METHODS

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

   _p( $expr )
   _P( $expr )
   escape( $expr )
   escape_xml( $expr )
   unescape_xml( $expr )
   encode_url( $url )
   decode_url( $url )
   checked( $expr )
   selected( $expr )
   disabled( $expr )
   nl2br( $text )
   text2html( $text )
   tagattr( $name, $expr, [$value] )
   tagattrs( %attrs )
   new_cycle( @items )

SEE ALSO

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

AUTHOR

       The CPAN version of Tenjin was forked by Ido Perlmuter <ido at ido50.net> from version 0.0.2 of the
       original plTenjin, which is developed by Makoto Kuwata at http://www.kuwata-lab.com/tenjin/
       <http://www.kuwata-lab.com/tenjin/>.

       Development of Tenjin is done with github at <http://github.com/ido50/Tenjin>.

       Tenjin is licensed under the MIT license.

               Copyright (c) 2007-2010 the aforementioned authors.

               Permission is hereby granted, free of charge, to any person obtaining
               a copy of this software and associated documentation files (the
               "Software"), to deal in the Software without restriction, including
               without limitation the rights to use, copy, modify, merge, publish,
               distribute, sublicense, and/or sell copies of the Software, and to
               permit persons to whom the Software is furnished to do so, subject to
               the following conditions:

               The above copyright notice and this permission notice shall be
               included in all copies or substantial portions of the Software.

               THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
               EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
               MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
               NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
               LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
               OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
               WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.