.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" 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 >0, 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Template::Document 3pm" .TH Template::Document 3pm "2014-06-27" "perl v5.24.1" "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" Template::Document \- Compiled template document object .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Template::Document; \& \& $doc = Template::Document\->new({ \& BLOCK => sub { # some perl code; return $some_text }, \& DEFBLOCKS => { \& header => sub { # more perl code; return $some_text }, \& footer => sub { # blah blah blah; return $some_text }, \& }, \& METADATA => { \& author => \*(AqAndy Wardley\*(Aq, \& version => 3.14, \& } \& }) || die $Template::Document::ERROR; \& \& print $doc\->process($context); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module defines an object class whose instances represent compiled template documents. The Template::Parser module creates a \&\f(CW\*(C`Template::Document\*(C'\fR instance to encapsulate a template as it is compiled into Perl code. .PP The constructor method, \fInew()\fR, expects a reference to a hash array containing the \f(CW\*(C`BLOCK\*(C'\fR, \f(CW\*(C`DEFBLOCKS\*(C'\fR and \f(CW\*(C`METADATA\*(C'\fR items. .PP The \f(CW\*(C`BLOCK\*(C'\fR item should contain a reference to a Perl subroutine or a textual representation of Perl code, as generated by the Template::Parser module. This is then evaluated into a subroutine reference using \f(CW\*(C`eval()\*(C'\fR. .PP The \f(CW\*(C`DEFLOCKS\*(C'\fR item should reference a hash array containing further named \&\f(CW\*(C`BLOCK\*(C'\fRs which may be defined in the template. The keys represent \f(CW\*(C`BLOCK\*(C'\fR names and the values should be subroutine references or text strings of Perl code as per the main \f(CW\*(C`BLOCK\*(C'\fR item. .PP The \f(CW\*(C`METADATA\*(C'\fR item should reference a hash array of metadata items relevant to the document. .PP The \fIprocess()\fR method can then be called on the instantiated \&\f(CW\*(C`Template::Document\*(C'\fR object, passing a reference to a Template::Context object as the first parameter. This will install any locally defined blocks (\f(CW\*(C`DEFBLOCKS\*(C'\fR) in the \f(CW\*(C`BLOCKS\*(C'\fR cache in the context (via a call to \&\fIvisit()\fR) so that they may be subsequently resolved by the context. The main \f(CW\*(C`BLOCK\*(C'\fR subroutine is then executed, passing the context reference on as a parameter. The text returned from the template subroutine is then returned by the \fIprocess()\fR method, after calling the context \fIleave()\fR method to permit cleanup and de-registration of named \f(CW\*(C`BLOCKS\*(C'\fR previously installed. .PP An \f(CW\*(C`AUTOLOAD\*(C'\fR method provides access to the \f(CW\*(C`METADATA\*(C'\fR items for the document. The Template::Service module installs a reference to the main \&\f(CW\*(C`Template::Document\*(C'\fR object in the stash as the \f(CW\*(C`template\*(C'\fR variable. This allows metadata items to be accessed from within templates, including \f(CW\*(C`PRE_PROCESS\*(C'\fR templates. .PP header: .PP .Vb 5 \& \&
\&