.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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" '' '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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "String::TT 3pm" .TH String::TT 3pm "2010-06-11" "perl v5.14.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" String::TT \- use TT to interpolate lexical variables .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use String::TT qw/tt strip/; \& \& sub foo { \& my $self = shift; \& return tt \*(Aqmy name is [% self.name %]!\*(Aq; \& } \& \& sub bar { \& my @args = @_; \& return strip tt q{ \& Args: [% args_a.join(",") %] \& } \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" String::TT exports a \f(CW\*(C`tt\*(C'\fR function, which takes a \s-1TT\s0 (Template Toolkit) template as its argument. It uses the current lexical scope to resolve variable references. So if you say: .PP .Vb 2 \& my $foo = 42; \& my $bar = 24; \& \& tt \*(Aq[% foo %] <\-> [% bar %]\*(Aq; .Ve .PP the result will be \f(CW\*(C`42 <\-> 24\*(C'\fR. .PP \&\s-1TT\s0 provides a slightly less rich namespace for variables than perl, so we have to do some mapping. Arrays are always translated from \&\f(CW@array\fR to \f(CW\*(C`array_a\*(C'\fR and hashes are always translated from \f(CW%hash\fR to \f(CW\*(C`hash_h\*(C'\fR. Scalars are special and retain their original name, but they also get a \f(CW\*(C`scalar_s\*(C'\fR alias. Here's an example: .PP .Vb 3 \& my $scalar = \*(Aqscalar\*(Aq; \& my @array = qw/array goes here/; \& my %hash = ( hashes => \*(Aqare fun\*(Aq ); \& \& tt \*(Aq[% scalar %] [% scalar_s %] [% array_a %] [% hash_h %]\*(Aq; .Ve .PP There is one special case, and that's when you have a scalar that is named like an existing array or hash's alias: .PP .Vb 2 \& my $foo_a = \*(Aqfoo_a\*(Aq; \& my @foo = qw/foo array/; \& \& tt \*(Aq[% foo_a %] [% foo_a_s %]\*(Aq; # foo_a is the array, foo_a_s is the scalar .Ve .PP In this case, the \f(CW\*(C`foo_a\*(C'\fR accessor for the \f(CW\*(C`foo_a\*(C'\fR scalar will not be generated. You will have to access it via \f(CW\*(C`foo_a_s\*(C'\fR. If you delete the array, though, then \f(CW\*(C`foo_a\*(C'\fR will refer to the scalar. .PP This is a very cornery case that you should never encounter unless you are weird. 99% of the time you will just use the variable name. .SH "EXPORT" .IX Header "EXPORT" None by default, but \f(CW\*(C`strip\*(C'\fR and \f(CW\*(C`tt\*(C'\fR are available. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .ie n .SS "tt $template" .el .SS "tt \f(CW$template\fP" .IX Subsection "tt $template" Treats \f(CW$template\fR as a Template Toolkit template, populated with variables from the current lexical scope. .ie n .SS "strip $text" .el .SS "strip \f(CW$text\fP" .IX Subsection "strip $text" Removes a leading empty line and common leading spaces on each line. For example, .PP .Vb 4 \& strip q{ \& This is a test. \& This is indented. \& }; .Ve .PP Will yield the string \f(CW"This is a test\en This is indented.\en"\fR. .PP This feature is designed to be used like: .PP .Vb 4 \& my $data = strip tt q{ \& This is a [% template %]. \& It is easy to read. \& }; .Ve .PP Instead of the ugly heredoc equivalent: .PP .Vb 4 \& my $data = tt <<\*(AqEOTT\*(Aq; \&This is a [% template %]. \&It looks like crap. \&EOTT .Ve .SH "HACKING" .IX Header "HACKING" If you want to pass args to the \s-1TT\s0 engine, override the \&\f(CW\*(C`_build_tt_engine\*(C'\fR function: .PP .Vb 2 \& local *String::TT::_build_tt_engine = sub { return Template\->new( ... ) } \& tt \*(Aqthis uses my engine\*(Aq; .Ve .SH "VERSION CONTROL" .IX Header "VERSION CONTROL" This module is hosted in the \f(CW\*(C`jrock.us\*(C'\fR git repository. You can view the history in your web browser at: .PP http://git.jrock.us/?p=String\-TT.git;a=summary .PP and you can clone the repository by running: .PP .Vb 1 \& git clone git://git.jrock.us/String\-TT .Ve .PP Patches welcome. .SH "AUTHOR" .IX Header "AUTHOR" Jonathan Rockway \f(CW\*(C`jrockway@cpan.org\*(C'\fR .SH "COPYRIGHT" .IX Header "COPYRIGHT" This module is copyright (c) 2008 Infinity Interactive. You may redistribute it under the same terms as Perl itself.