.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Tenjin::Context 3pm" .TH Tenjin::Context 3pm "2016-05-17" "perl v5.22.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Tenjin::Context \- In charge of managing variables passed to Tenjin templates. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& # this module is used internally, but if you insist, it is \& # in charge of the context object: \& \& # in your templates (unnecessary, for illustration purposes): \& [== $_context\->{title} =] \& # instead use: \& [== $title =] .Ve .SH "DESCRIPTION" .IX Header "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 \*(L"standalone variables\*(R" named for each key in the hash-ref. .PP 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. .PP Finally, this module makes the Tenjin utility methods of Tenjin::Util available natively inside templates. See Tenjin::Util for more info. .SH "INTERNAL METHODS" .IX Header "INTERNAL METHODS" .SS "new( [\e%vars] )" .IX Subsection "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 \f(CW$vars\fR hash-ref is passed to the constructor, it will be augmented into the created object. .PP To illustrate the context object, suppose it looks like so: .PP .Vb 5 \& { \& scalar => \*(AqI am a scalar\*(Aq, \& arrayref => [qw/I am an array/], \& hashref => { i => \*(Aqam\*(Aq, a => \*(Aqhash\-ref\*(Aq }, \& } .Ve .PP Then the variables \f(CW$scalar\fR, \f(CW$arrayref\fR and \f(CW$hashref\fR will be available for direct usage inside your templates, and you can dereference the variables normally (i.e. \f(CW@$arrayref\fR and \f(CW%$hashref\fR). .ie n .SS "evaluate( $script, $template_name )" .el .SS "evaluate( \f(CW$script\fP, \f(CW$template_name\fP )" .IX Subsection "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 \f(CW\*(C`use strict\*(C'\fR, the script will be \f(CW\*(C`eval\*(C'\fRed under \f(CW\*(C`use strict\*(C'\fR. .ie n .SS "to_func( $script, [$filename] )" .el .SS "to_func( \f(CW$script\fP, [$filename] )" .IX Subsection "to_func( $script, [$filename] )" This method receives the script created when reading a template and wraps it in a subroutine, \f(CW\*(C`eval\*(C'\fRs it and returns the rendered output. This method is called when compiling the template. .SS "\fI_build_decl()\fP" .IX Subsection "_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. .SH "UTILITY METHODS" .IX Header "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. .ie n .SS "_p( $expr )" .el .SS "_p( \f(CW$expr\fP )" .IX Subsection "_p( $expr )" .ie n .SS "_P( $expr )" .el .SS "_P( \f(CW$expr\fP )" .IX Subsection "_P( $expr )" .ie n .SS "escape( $expr )" .el .SS "escape( \f(CW$expr\fP )" .IX Subsection "escape( $expr )" .ie n .SS "escape_xml( $expr )" .el .SS "escape_xml( \f(CW$expr\fP )" .IX Subsection "escape_xml( $expr )" .ie n .SS "unescape_xml( $expr )" .el .SS "unescape_xml( \f(CW$expr\fP )" .IX Subsection "unescape_xml( $expr )" .ie n .SS "encode_url( $url )" .el .SS "encode_url( \f(CW$url\fP )" .IX Subsection "encode_url( $url )" .ie n .SS "decode_url( $url )" .el .SS "decode_url( \f(CW$url\fP )" .IX Subsection "decode_url( $url )" .ie n .SS "checked( $expr )" .el .SS "checked( \f(CW$expr\fP )" .IX Subsection "checked( $expr )" .ie n .SS "selected( $expr )" .el .SS "selected( \f(CW$expr\fP )" .IX Subsection "selected( $expr )" .ie n .SS "disabled( $expr )" .el .SS "disabled( \f(CW$expr\fP )" .IX Subsection "disabled( $expr )" .ie n .SS "nl2br( $text )" .el .SS "nl2br( \f(CW$text\fP )" .IX Subsection "nl2br( $text )" .ie n .SS "text2html( $text )" .el .SS "text2html( \f(CW$text\fP )" .IX Subsection "text2html( $text )" .ie n .SS "tagattr( $name, $expr, [$value] )" .el .SS "tagattr( \f(CW$name\fP, \f(CW$expr\fP, [$value] )" .IX Subsection "tagattr( $name, $expr, [$value] )" .ie n .SS "tagattrs( %attrs )" .el .SS "tagattrs( \f(CW%attrs\fP )" .IX Subsection "tagattrs( %attrs )" .ie n .SS "new_cycle( @items )" .el .SS "new_cycle( \f(CW@items\fP )" .IX Subsection "new_cycle( @items )" .SH "SEE ALSO" .IX Header "SEE ALSO" Tenjin, Tenjin::Util, Tenjin::Template. .SH "AUTHOR, LICENSE AND COPYRIGHT" .IX Header "AUTHOR, LICENSE AND COPYRIGHT" See Tenjin.