.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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 .. .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 "String::TT 3pm" .TH String::TT 3pm "2022-06-17" "perl v5.34.0" "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 .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.