home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _ca14b4c69ef24aaa8fe082001fbe3400 < prev    next >
Text File  |  2000-03-23  |  64KB  |  1,259 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Text::Template - Expand template text with embedded Perl</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Text::Template - Expand template text with embedded Perl</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#version">VERSION</A></LI>
  24.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  25.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  26.     <UL>
  27.  
  28.         <LI><A HREF="#example">Example</A></LI>
  29.         <LI><A HREF="#philosophy">Philosophy</A></LI>
  30.     </UL>
  31.  
  32.     <LI><A HREF="#details">Details</A></LI>
  33.     <UL>
  34.  
  35.         <LI><A HREF="#template parsing">Template Parsing</A></LI>
  36.         <LI><A HREF="#the $out variable">The <CODE>$OUT</CODE> variable</A></LI>
  37.         <LI><A HREF="#general remarks">General Remarks</A></LI>
  38.         <LI><A HREF="#new"><CODE>new</CODE></A></LI>
  39.         <LI><A HREF="#compile"><CODE>compile</CODE></A></LI>
  40.         <LI><A HREF="#fill_in"><CODE>fill_in</CODE></A></LI>
  41.     </UL>
  42.  
  43.     <LI><A HREF="#convenience functions">Convenience Functions</A></LI>
  44.     <UL>
  45.  
  46.         <LI><A HREF="#fill_this_in"><CODE>fill_this_in</CODE></A></LI>
  47.         <LI><A HREF="#fill_in_string"><CODE>fill_in_string</CODE></A></LI>
  48.         <LI><A HREF="#fill_in_file"><CODE>fill_in_file</CODE></A></LI>
  49.         <LI><A HREF="#including files into templates">Including files into templates</A></LI>
  50.     </UL>
  51.  
  52.     <LI><A HREF="#miscellaneous">Miscellaneous</A></LI>
  53.     <UL>
  54.  
  55.         <LI><A HREF="#my variables"><A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A> variables</A></LI>
  56.         <LI><A HREF="#security matters">Security Matters</A></LI>
  57.         <LI><A HREF="#alternative delimiters">Alternative Delimiters</A></LI>
  58.         <LI><A HREF="#prepend feature and using strict in templates"><CODE>PREPEND</CODE> feature and using <CODE>strict</CODE> in templates</A></LI>
  59.         <LI><A HREF="#prepending in derived classes">Prepending in Derived Classes</A></LI>
  60.         <LI><A HREF="#javascript">JavaScript</A></LI>
  61.         <LI><A HREF="#shut up!">Shut Up!</A></LI>
  62.         <LI><A HREF="#compatibility">Compatibility</A></LI>
  63.         <LI><A HREF="#backslash processing">Backslash Processing</A></LI>
  64.         <LI><A HREF="#a short note about $text::template::error">A short note about <CODE>$Text::Template::ERROR</CODE></A></LI>
  65.         <LI><A HREF="#sticky widgets in template files">Sticky Widgets in Template Files</A></LI>
  66.         <LI><A HREF="#author">Author</A></LI>
  67.         <LI><A HREF="#support">Support?</A></LI>
  68.         <LI><A HREF="#thanks">Thanks</A></LI>
  69.         <LI><A HREF="#bugs and caveats">Bugs and Caveats</A></LI>
  70.     </UL>
  71.  
  72. </UL>
  73. <!-- INDEX END -->
  74.  
  75. <HR>
  76. <P>
  77. <H1><A NAME="name">NAME</A></H1>
  78. <P>Text::Template - Expand template text with embedded Perl</P>
  79. <P>
  80. <HR>
  81. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  82. <UL>
  83. <LI>Windows</LI>
  84. </UL>
  85. <HR>
  86. <H1><A NAME="version">VERSION</A></H1>
  87. <P>This file documents <CODE>Text::Template</CODE> version <STRONG>1.23</STRONG></P>
  88. <P>
  89. <HR>
  90. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  91. <PRE>
  92.  use Text::Template;</PRE>
  93. <PRE>
  94.  $template = new Text::Template (TYPE => FILE,  SOURCE => 'filename.tmpl');
  95.  $template = new Text::Template (TYPE => ARRAY, SOURCE => [ ... ] );
  96.  $template = new Text::Template (TYPE => FILEHANDLE, SOURCE => $fh );
  97.  $template = new Text::Template (TYPE => STRING, SOURCE => '...' );
  98.  $template = new Text::Template (PREPEND => q{use strict;}, ...);</PRE>
  99. <PRE>
  100.  # Use a different template file syntax:
  101.  $template = new Text::Template (DELIMITERS => [$open, $close], ...);</PRE>
  102. <PRE>
  103.  $recipient = 'King';
  104.  $text = $template->fill_in();  # Replaces `{$recipient}' with `King'
  105.  print $text;</PRE>
  106. <PRE>
  107.  $T::recipient = 'Josh';
  108.  $text = $template->fill_in(PACKAGE => T);</PRE>
  109. <PRE>
  110.  $hash = { recipient => 'Abed-Nego' };
  111.  $text = $template->fill_in(HASH => $hash, ...); # Recipient is Abed-Nego</PRE>
  112. <PRE>
  113.  # Call &callback in case of programming errors in template
  114.  $text = $template->fill_in(BROKEN => \&callback, BROKEN_ARG => [...]);</PRE>
  115. <PRE>
  116.  # Evaluate program fragments in Safe compartment with restricted permissions
  117.  $text = $template->fill_in(SAFE => $compartment, ...);</PRE>
  118. <PRE>
  119.  # Print result text instead of returning it
  120.  $success = $template->fill_in(OUTPUT => \*FILEHANDLE, ...);</PRE>
  121. <PRE>
  122.  # Parse template with different template file syntax:
  123.  $text = $template->fill_in(DELIMITERS => [$open, $close], ...);
  124.  # Note that this is *faster* than using the default delimiters</PRE>
  125. <PRE>
  126.  # Prepend specified perl code to each fragment before evaluating:
  127.  $text = $template->fill_in(PREPEND => q{use strict 'vars';}, ...);</PRE>
  128. <PRE>
  129.  use Text::Template 'fill_in_string';
  130.  $text = fill_in_string( <<EOM, PACKAGE => 'T', ...);
  131.  Dear {$recipient},
  132.  Pay me at once.
  133.         Love, 
  134.          G.V.
  135.  EOM</PRE>
  136. <PRE>
  137.  use Text::Template 'fill_in_file';
  138.  $text = fill_in_file($filename, ...);</PRE>
  139. <PRE>
  140.  # All templates will always have `use strict vars' attached to all fragments
  141.  Text::Template->always_prepend(q{use strict 'vars';});</PRE>
  142. <P>
  143. <HR>
  144. <H1><A NAME="description">DESCRIPTION</A></H1>
  145. <P>This is a library for generating form letters, building HTML pages, or
  146. filling in templates generally.  A `template' is a piece of text that
  147. has little Perl programs embedded in it here and there.  When you
  148. `fill in' a template, you evaluate the little programs and replace
  149. them with their values.</P>
  150. <P>You can store a template in a file outside your program.  People can
  151. modify the template without modifying the program.  You can separate
  152. the formatting details from the main code, and put the formatting
  153. parts of the program into the template.  That prevents code bloat and
  154. encourages functional separation.</P>
  155. <P>
  156. <H2><A NAME="example">Example</A></H2>
  157. <P>Here's an example of a template, which we'll suppose is stored in the
  158. file <CODE>formletter.tmpl</CODE>:</P>
  159. <PRE>
  160.         Dear {$title} {$lastname},</PRE>
  161. <PRE>
  162.         It has come to our attention that you are delinquent in your
  163.         {$monthname[$last_paid_month]} payment.  Please remit
  164.         ${sprintf("%.2f", $amount)} immediately, or your patellae may
  165.         be needlessly endangered.</PRE>
  166. <PRE>
  167.                         Love,</PRE>
  168. <PRE>
  169.                         Mark "Vizopteryx" Dominus</PRE>
  170. <P>The result of filling in this template is a string, which might look
  171. something like this:</P>
  172. <PRE>
  173.         Dear Mr. Gates,</PRE>
  174. <PRE>
  175.         It has come to our attention that you are delinquent in your
  176.         February payment.  Please remit
  177.         $392.12 immediately, or your patellae may
  178.         be needlessly endangered.</PRE>
  179. <PRE>
  180.                         Love,</PRE>
  181. <PRE>
  182.                         Mark "Vizopteryx" Dominus</PRE>
  183. <P>Here is a complete program that transforms the example
  184. template into the example result, and prints it out:</P>
  185. <PRE>
  186.         use Text::Template;</PRE>
  187. <PRE>
  188.         my $template = new Text::Template (SOURCE => 'formletter.tmpl')
  189.           or die "Couldn't construct template: $Text::Template::ERROR";</PRE>
  190. <PRE>
  191.         my @monthname = qw(January February March April May June
  192.                            July August September October November December);
  193.         my %vars = (title => 'Mr.',
  194.                     firstname => 'Bill',
  195.                     lastname => 'Gates',
  196.                     last_paid_month => 1,   # February
  197.                     amount => 392.12,
  198.                     monthname => \@monthname,
  199.                    );</PRE>
  200. <PRE>
  201.         my $result = $template->fill_in(HASH => \%vars);</PRE>
  202. <PRE>
  203.         if (defined $result) { print $result }
  204.         else { die "Couldn't fill in template: $Text::Template::ERROR" }</PRE>
  205. <P>
  206. <H2><A NAME="philosophy">Philosophy</A></H2>
  207. <P>When people make a template module like this one, they almost always
  208. start by inventing a special syntax for substitutions.  For example,
  209. they build it so that a string like <CODE>%%VAR%%</CODE> is replaced with the
  210. value of <CODE>$VAR</CODE>.  Then they realize the need extra formatting, so
  211. they put in some special syntax for formatting.  Then they need a
  212. loop, so they invent a loop syntax.  Pretty soon they have a new
  213. little template language.</P>
  214. <P>This approach has two problems: First, their little language is
  215. crippled. If you need to do something the author hasn't thought of,
  216. you lose.  Second: Who wants to learn another language?  You already
  217. know Perl, so why not use it?</P>
  218. <P><CODE>Text::Template</CODE> templates are programmed in <EM>Perl</EM>.  You embed Perl
  219. code in your template, with <CODE>{</CODE> at the beginning and <CODE>}</CODE> at the end.
  220. If you want a variable interpolated, you write it the way you would in
  221. Perl.  If you need to make a loop, you can use any of the Perl loop
  222. constructions.  All the Perl built-in functions are available.</P>
  223. <P>
  224. <HR>
  225. <H1><A NAME="details">Details</A></H1>
  226. <P>
  227. <H2><A NAME="template parsing">Template Parsing</A></H2>
  228. <P>The <CODE>Text::Template</CODE> module scans the template source.  An open brace
  229. <CODE>{</CODE> begins a program fragment, which continues until the matching
  230. close brace <CODE>}</CODE>.  When the template is filled in, the program
  231. fragments are evaluated, and each one is replaced with the resulting
  232. value to yield the text that is returned.</P>
  233. <P>A backslash <CODE>\</CODE> in front of a brace (or another backslash that is in
  234. front of a brace) escapes its special meaning.  The result of filling
  235. out this template:</P>
  236. <PRE>
  237.         \{ The sum of 1 and 2 is {1+2}  \}</PRE>
  238. <P>is</P>
  239. <PRE>
  240.         { The sum of 1 and 2 is 3  }</PRE>
  241. <P>If you have an unmatched brace, <CODE>Text::Template</CODE> will return a
  242. failure code and a warning about where the problem is.  Backslashes
  243. that do not precede a brace are passed through unchanged.  If you have
  244. a template like this:</P>
  245. <PRE>
  246.         { "String that ends in a newline.\n" }</PRE>
  247. <P>The backslash inside the string is passed through to Perl unchanged,
  248. so the <CODE>\n</CODE> really does turn into a newline.  See the note at the end
  249. for details about the way backslashes work.  Backslash processing is
  250. <EM>not</EM> done when you specify alternative delimiters with the
  251. <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A> option.  (See <A HREF="#alternative delimiters">Alternative Delimiters</A>, below.)</P>
  252. <P>Each program fragment should be a sequence of Perl statements, which
  253. are evaluated the usual way.  The result of the last statement
  254. executed will be evaluted in scalar context; the result of this
  255. statement is a string, which is interpolated into the template in
  256. place of the program fragment itself.</P>
  257. <P>The fragments are evaluated in order, and side effects from earlier
  258. fragments will persist into later fragments:</P>
  259. <PRE>
  260.         {$x = @things; ''}The Lord High Chamberlain has gotten {$x}
  261.         things for me this year.  
  262.         { $diff = $x - 17; 
  263.           $more = 'more'
  264.           if ($diff == 0) {
  265.             $diff = 'no';
  266.           } elsif ($diff < 0) {
  267.             $more = 'fewer';
  268.           } 
  269.           '';
  270.         } 
  271.         That is {$diff} {$more} than he gave me last year.</PRE>
  272. <P>The value of <CODE>$x</CODE> set in the first line will persist into the next
  273. fragment that begins on the third line, and the values of <CODE>$diff</CODE> and
  274. <CODE>$more</CODE> set in the second fragment will persist and be interpolated
  275. into the last line.  The output will look something like this:</P>
  276. <PRE>
  277.         The Lord High Chamberlain has gotten 42
  278.         things for me this year.</PRE>
  279. <PRE>
  280.         That is 35 more than he gave me last year.</PRE>
  281. <P>That is all the syntax there is.</P>
  282. <P>
  283. <H2><A NAME="the $out variable">The <CODE>$OUT</CODE> variable</A></H2>
  284. <P>There is one special trick you can play in a template.  Here is the
  285. motivation for it:  Suppose you are going to pass an array, <CODE>@items</CODE>,
  286. into the template, and you want the template to generate a bulleted
  287. list with a header, like this:</P>
  288. <PRE>
  289.         Here is a list of the things I have got for you since 1907:
  290.           * Ivory
  291.           * Apes
  292.           * Peacocks
  293.           * ...</PRE>
  294. <P>One way to do it is with a template like this:</P>
  295. <PRE>
  296.         Here is a list of the things I have got for you since 1907:
  297.         { my $blist = '';
  298.           foreach $i (@items) {
  299.             $blist .= qq{  * $i\n};
  300.           }    
  301.           $blist;
  302.         }</PRE>
  303. <P>Here we construct the list in a variable called <CODE>$blist</CODE>, which we
  304. return at the end.  This is a little cumbersome.  There is a shortcut.</P>
  305. <P>Inside of templates, there is a special variable called <CODE>$OUT</CODE>.
  306. Anything you append to this variable will appear in the output of the
  307. template.  Also, if you use <CODE>$OUT</CODE> in a program fragment, the normal
  308. behavior, of replacing the fragment with its return value, is
  309. disabled; instead the fragment is replaced with the value of <CODE>$OUT</CODE>.
  310. This means that you can write the template above like this:</P>
  311. <PRE>
  312.         Here is a list of the things I have got for you since 1907:
  313.         { foreach $i (@items) {
  314.             $OUT .= "  * $i\n";
  315.           }    
  316.         }</PRE>
  317. <P><CODE>$OUT</CODE> is reinitialized to the empty string at the start of each
  318. program fragment.  It is private to <CODE>Text::Template</CODE>, so 
  319. you can't use a variable named <CODE>$OUT</CODE> in your template without
  320. invoking the special behavior.</P>
  321. <P>
  322. <H2><A NAME="general remarks">General Remarks</A></H2>
  323. <P>All <CODE>Text::Template</CODE> functions return <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> on failure, and set the
  324. variable <CODE>$Text::Template::ERROR</CODE> to contain an explanation of what
  325. went wrong.  For example, if you try to create a template from a file
  326. that does not exist, <CODE>$Text::Template::ERROR</CODE> will contain something like:</P>
  327. <PRE>
  328.         Couldn't open file xyz.tmpl: No such file or directory</PRE>
  329. <P>
  330. <H2><A NAME="new"><CODE>new</CODE></A></H2>
  331. <PRE>
  332.         $template = new Text::Template ( TYPE => ..., SOURCE => ... );</PRE>
  333. <P>This creates and returns a new template object.  <CODE>new</CODE> returns
  334. <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> and sets <CODE>$Text::Template::ERROR</CODE> if it can't create the
  335. template object.  <CODE>SOURCE</CODE> says where the template source code will
  336. come from.  <CODE>TYPE</CODE> says what kind of object the source is.</P>
  337. <P>The most common type of source is a file:</P>
  338. <PRE>
  339.         new Text::Template ( TYPE => 'FILE', SOURCE => $filename );</PRE>
  340. <P>This reads the template from the specified file.  The filename is
  341. opened with the Perl <A HREF="../../../lib/Pod/perlfunc.html#item_open"><CODE>open</CODE></A> command, so it can be a pipe or anything
  342. else that makes sense with <A HREF="../../../lib/Pod/perlfunc.html#item_open"><CODE>open</CODE></A>.</P>
  343. <P>The <CODE>TYPE</CODE> can also be <CODE>STRING</CODE>, in which case the <CODE>SOURCE</CODE> should
  344. be a string:</P>
  345. <PRE>
  346.         new Text::Template ( TYPE => 'STRING', 
  347.                              SOURCE => "This is the actual template!" );</PRE>
  348. <P>The <CODE>TYPE</CODE> can be <CODE>ARRAY</CODE>, in which case the source should be a
  349. reference to an array of strings.  The concatenation of these strings
  350. is the template:</P>
  351. <PRE>
  352.         new Text::Template ( TYPE => 'ARRAY', 
  353.                              SOURCE => [ "This is ", "the actual", 
  354.                                          " template!",
  355.                                        ]
  356.                            );</PRE>
  357. <P>The <CODE>TYPE</CODE> can be FILEHANDLE, in which case the source should be an
  358. open filehandle (such as you got from the <CODE>FileHandle</CODE> or <CODE>IO::*</CODE>
  359. packages, or a glob, or a reference to a glob).  In this case
  360. <CODE>Text::Template</CODE> will read the text from the filehandle up to
  361. end-of-file, and that text is the template:</P>
  362. <PRE>
  363.         # Read template source code from STDIN:
  364.         new Text::Template ( TYPE => 'FILEHANDLE', 
  365.                              SOURCE => \*STDIN  );</PRE>
  366. <P>If you omit the <CODE>TYPE</CODE> attribute, it's taken to be <CODE>FILE</CODE>.
  367. <CODE>SOURCE</CODE> is required.  If you omit it, the program will abort.</P>
  368. <P>The words <CODE>TYPE</CODE> and <CODE>SOURCE</CODE> can be spelled any of the following ways:</P>
  369. <PRE>
  370.         TYPE    SOURCE
  371.         Type    Source
  372.         type    source
  373.         -TYPE   -SOURCE
  374.         -Type   -Source
  375.         -type   -source</PRE>
  376. <P>Pick a style you like and stick with it.</P>
  377. <DL>
  378. <DT><STRONG><A NAME="item_DELIMITERS"><CODE>DELIMITERS</CODE></A></STRONG><BR>
  379. <DD>
  380. You may also add a <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A> option.  If this option is present,
  381. its value should be a reference to an array of two strings.  The first
  382. string is the string that signals the beginning of each program
  383. fragment, and the second string is the string that signals the end of
  384. each program fragment.  See <A HREF="#alternative delimiters">Alternative Delimiters</A>, below.
  385. <P></P></DL>
  386. <P>
  387. <H2><A NAME="compile"><CODE>compile</CODE></A></H2>
  388. <PRE>
  389.         $template->compile()</PRE>
  390. <P>Loads all the template text from the template's source, parses and
  391. compiles it.  If successful, returns true; otherwise returns false and
  392. sets <CODE>$Text::Template::ERROR</CODE>.  If the template is already compiled,
  393. it returns true and does nothing.</P>
  394. <P>You don't usually need to invoke this function, because <CODE>fill_in</CODE>
  395. (see below) compiles the template if it isn't compiled already.</P>
  396. <P>If there is an argument to this function, it must be a reference to an
  397. array containing alternative delimiter strings.  See <CODE>"Alternative
  398. Delimiters"</CODE>, below.</P>
  399. <P>
  400. <H2><A NAME="fill_in"><CODE>fill_in</CODE></A></H2>
  401. <PRE>
  402.         $template->fill_in(OPTIONS);</PRE>
  403. <P>Fills in a template.  Returns the resulting text if successful.
  404. Otherwise, returns <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A>  and sets <CODE>$Text::Template::ERROR</CODE>.</P>
  405. <P>The <EM>OPTIONS</EM> are a hash, or a list of key-value pairs.  You can
  406. write the key names in any of the six usual styles as above; this
  407. means that where this manual says <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A> (for example) you can
  408. actually use any of</P>
  409. <PRE>
  410.         PACKAGE Package package -PACKAGE -Package -package</PRE>
  411. <P>Pick a style you like and stick with it.  The all-lowercase versions
  412. may yield spurious warnings about</P>
  413. <PRE>
  414.         Ambiguous use of package => resolved to "package"</PRE>
  415. <P>so you might like to avoid them and use the capitalized versions.</P>
  416. <P>At present, there are seven legal options:  <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A>, <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A>,
  417. <A HREF="#item_BROKEN_ARG"><CODE>BROKEN_ARG</CODE></A>, <A HREF="#item_SAFE"><CODE>SAFE</CODE></A>, <A HREF="#item_HASH"><CODE>HASH</CODE></A>, <A HREF="#item_OUTPUT"><CODE>OUTPUT</CODE></A>, and <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A>.</P>
  418. <DL>
  419. <DT><STRONG><A NAME="item_PACKAGE"><CODE>PACKAGE</CODE></A></STRONG><BR>
  420. <DD>
  421. <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A> specifies the name of a package in which the program
  422. fragments should be evaluated.  The default is to use the package from
  423. which <CODE>fill_in</CODE> was called.  For example, consider this template:
  424. <PRE>
  425.         The value of the variable x is {$x}.</PRE>
  426. <P>If you use <CODE>$template->fill_in(PACKAGE => 'R')</CODE> , then the <CODE>$x</CODE> in
  427. the template is actually replaced with the value of <CODE>$R::x</CODE>.  If you
  428. omit the <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A> option, <CODE>$x</CODE> will be replaced with the value of
  429. the <CODE>$x</CODE> variable in the package that actually called <CODE>fill_in</CODE>.</P>
  430. <P>You should almost always use <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A>.  If you don't, and your
  431. template makes changes to variables, those changes will be propagated
  432. back into the main program.  Evaluating the template in a private
  433. package helps prevent this.  The template can still modify variables
  434. in your program if it wants to, but it will have to do so explicitly.
  435. See the section at the end on `Security'.</P>
  436. <P>Here's an example of using <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A>:</P>
  437. <PRE>
  438.         Your Royal Highness,</PRE>
  439. <PRE>
  440.         Enclosed please find a list of things I have gotten
  441.         for you since 1907:</PRE>
  442. <PRE>
  443.         { foreach $item (@items) {
  444.             $item_no++;
  445.             $OUT .= " $item_no. \u$item\n";
  446.           }
  447.         }</PRE>
  448. <PRE>
  449.         Signed,
  450.         Lord High Chamberlain</PRE>
  451. <P>We want to pass in an array which will be assigned to the array
  452. <CODE>@items</CODE>.  Here's how to do that:</P>
  453. <PRE>
  454.         @items = ('ivory', 'apes', 'peacocks', );
  455.         $template->fill_in();</PRE>
  456. <P>This is not very safe.  The reason this isn't as safe is that if you
  457. had a variable named <CODE>$item_no</CODE> in scope in your program at the point
  458. you called <CODE>fill_in</CODE>, its value would be clobbered by the act of
  459. filling out the template.  The problem is the same as if you had
  460. written a subroutine that used those variables in the same way that
  461. the template does.  (<CODE>$OUT</CODE> is special in templates and is always
  462. safe.)</P>
  463. <P>One solution to this is to make the <CODE>$item_no</CODE> variable private to the
  464. template by declaring it with <A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A>.  If the template does this, you
  465. are safe.</P>
  466. <P>But if you use the <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A> option, you will probably be safe even
  467. if the template does <EM>not</EM> declare its variables with <A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A>:</P>
  468. <PRE>
  469.         @Q::items = ('ivory', 'apes', 'peacocks', );
  470.         $template->fill_in(PACKAGE => 'Q');</PRE>
  471. <P>In this case the template will clobber the variable <CODE>$Q::item_no</CODE>,
  472. which is not related to the one your program was using.</P>
  473. <P>Templates cannot affect variables in the main program that are
  474. declared with <A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A>, unless you give the template references to those
  475. variables.</P>
  476. <P></P>
  477. <DT><STRONG><A NAME="item_HASH"><CODE>HASH</CODE></A></STRONG><BR>
  478. <DD>
  479. You may not want to put the template variables into a package.
  480. Packages can be hard to manage:  You can't copy them, for example.
  481. <A HREF="#item_HASH"><CODE>HASH</CODE></A> provides an alternative.
  482. <P>The value for <A HREF="#item_HASH"><CODE>HASH</CODE></A> should be a reference to a hash that maps
  483. variable names to values.  For example,</P>
  484. <PRE>
  485.         $template->fill_in(HASH => { recipient => "The King",
  486.                                      items => ['gold', 'frankincense', 'myrrh']
  487.                                    });</PRE>
  488. <P>will fill out the template and use <CODE>"The King"</CODE> as the value of
  489. <CODE>$recipient</CODE> and the list of items as the value of <CODE>@items</CODE>.</P>
  490. <P>The full details of how it works are a little involved, so you might
  491. want to skip to the next section.</P>
  492. <P>Suppose the key in the hash is <EM>key</EM> and the value is <EM>value</EM>.</P>
  493. <UL>
  494. <LI>
  495. If the <EM>value</EM> is <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A>, then any variables named <CODE>$key</CODE>,
  496. <CODE>@key</CODE>, <CODE>%key</CODE>, etc., are undefined.
  497. <P></P>
  498. <LI>
  499. If the <EM>value</EM> is a string or a number, then <CODE>$key</CODE> is set to that
  500. value in the template.
  501. <P></P>
  502. <LI>
  503. If the <EM>value</EM> is a reference to an array, then <CODE>@key</CODE> is set to
  504. that array.  If the <EM>value</EM> is a reference to a hash, then <CODE>%key</CODE> is
  505. set to that hash.  Similarly if <EM>value</EM> is any other kind of
  506. reference.  This means that
  507. <PRE>
  508.         var => "foo"</PRE>
  509. <P>and</P>
  510. <PRE>
  511.         var => \"foo"</PRE>
  512. <P>have almost exactly the same effect.  (The difference is that in the
  513. former case, the value is copied, and in the latter case it is
  514. aliased.)</P>
  515. <P></P></UL>
  516. <P>Normally, the way this works is by allocating a private package,
  517. loading all the variables into the package, and then filling out the
  518. template as if you had specified that package.  A new package is
  519. allocated each time.  However, if you <EM>also</EM> use the <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A>
  520. option, <CODE>Text::Template</CODE> loads the variables into the package you
  521. specified, and they stay there after the call returns.  Subsequent
  522. calls to <CODE>fill_in</CODE> that use the same package will pick up the values
  523. you loaded in.</P>
  524. <P>If the argument of <A HREF="#item_HASH"><CODE>HASH</CODE></A> is a reference to an array instead of a
  525. reference to a hash, then the array should contain a list of hashes
  526. whose contents are loaded into the template package one after the
  527. other.  You can use this feature if you want to combine several sets
  528. of variables.  For example, one set of variables might be the defaults
  529. for a fill-in form, and the second set might be the user inputs, which
  530. override the defaults when they are present:</P>
  531. <PRE>
  532.         $template->fill_in(HASH => [\%defaults, \%user_input]);</PRE>
  533. <P>You can also use this to set two variables with the same name:</P>
  534. <PRE>
  535.         $template->fill_in(HASH => [{ v => "The King" },
  536.                                     { v => [1,2,3] },
  537.                                    ]
  538.                           );</PRE>
  539. <P>This sets <CODE>$v</CODE> to <CODE>"The King"</CODE> and <CODE>@v</CODE> to <CODE>(1,2,3)</CODE>.</P>
  540. <DT><STRONG><A NAME="item_BROKEN"><CODE>BROKEN</CODE></A></STRONG><BR>
  541. <DD>
  542. If any of the program fragments fails to compile or aborts for any
  543. reason, and you have set the <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> option to a function reference,
  544. <CODE>Text::Template</CODE> will invoke the function.  This function is called
  545. the <EM><A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function</EM>.  The <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function will tell
  546. <CODE>Text::Template</CODE> what to do next.
  547. <P>If the <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function returns <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A>, <CODE>Text::Template</CODE> will
  548. immediately abort processing the template and return the text that it
  549. has accumulated so far.  If your function does this, it should set a
  550. flag that you can examine after <CODE>fill_in</CODE> returns so that you can
  551. tell whether there was a premature return or not.</P>
  552. <P>If the <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function returns any other value, that value will be
  553. interpolated into the template as if that value had been the return
  554. value of the program fragment to begin with.  For example, if the
  555. <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function returns an error string, the error string will be
  556. interpolated into the output of the template in place of the program
  557. fragment that cased the error.</P>
  558. <P>If you don't specify a <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function, <CODE>Text::Template</CODE> supplies
  559. a default one that returns something like</P>
  560. <PRE>
  561.         Program fragment at line 17 delivered error ``Illegal
  562.         division by 0''</PRE>
  563. <P>Since this is interpolated into the template at the place the error
  564. occurred, a template like this one:</P>
  565. <PRE>
  566.         (3+4)*5 = { 3+4)*5 }</PRE>
  567. <P>yields this result:</P>
  568. <PRE>
  569.         (3+4)*5 = Program fragment at line 1 delivered error
  570.         ``syntax error''</PRE>
  571. <P>If you specify a value for the <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> attribute, it should be a
  572. reference to a function that <CODE>fill_in</CODE> can call instead of the
  573. default function.</P>
  574. <P><CODE>fill_in</CODE> will pass a hash to the <CODE>broken</CODE> function.
  575. The hash will have at least these three members:</P>
  576. <DL>
  577. <DT><STRONG><A NAME="item_text"><CODE>text</CODE></A></STRONG><BR>
  578. <DD>
  579. The source code of the program fragment that failed
  580. <P></P>
  581. <DT><STRONG><A NAME="item_error"><CODE>error</CODE></A></STRONG><BR>
  582. <DD>
  583. The text of the error message (<CODE>$@</CODE>) generated by eval
  584. <P></P>
  585. <DT><STRONG><A NAME="item_lineno"><CODE>lineno</CODE></A></STRONG><BR>
  586. <DD>
  587. The line number of the template data at which the  program fragment
  588. began
  589. <P></P></DL>
  590. <P>There may also be an <CODE>arg</CODE> member.  See <A HREF="#item_BROKEN_ARG"><CODE>BROKEN_ARG</CODE></A>, below</P>
  591. <DT><STRONG><A NAME="item_BROKEN_ARG"><CODE>BROKEN_ARG</CODE></A></STRONG><BR>
  592. <DD>
  593. If you supply the <A HREF="#item_BROKEN_ARG"><CODE>BROKEN_ARG</CODE></A> option to <CODE>fill_in</CODE>, the value of the
  594. option is passed to the <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function whenever it is called.  The
  595. default <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function ignores the <A HREF="#item_BROKEN_ARG"><CODE>BROKEN_ARG</CODE></A>, but you can
  596. write a custom <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function that uses the <A HREF="#item_BROKEN_ARG"><CODE>BROKEN_ARG</CODE></A> to get
  597. more information about what went wrong.
  598. <P>The <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function could also use the <A HREF="#item_BROKEN_ARG"><CODE>BROKEN_ARG</CODE></A> as a reference
  599. to store an error message or some other information that it wants to
  600. communicate back to the caller.  For example:</P>
  601. <PRE>
  602.         $error = '';</PRE>
  603. <PRE>
  604.         sub my_broken { 
  605.            my %args = @_;
  606.            my $err_ref = $args{arg};
  607.            ...
  608.            $$err_ref = "Some error message";
  609.            return undef;
  610.         }</PRE>
  611. <PRE>
  612.         $template->fill_in(BROKEN => \&my_broken,
  613.                            BROKEN_ARG => \$error,
  614.                           );</PRE>
  615. <PRE>
  616.         if ($error) {
  617.           die "It didn't work: $error";
  618.         }</PRE>
  619. <P>If one of the program fragments in the template fails, it will call
  620. the <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> function, <CODE>my_broken</CODE>, and pass it the <A HREF="#item_BROKEN_ARG"><CODE>BROKEN_ARG</CODE></A>,
  621. which is a reference to <CODE>$error</CODE>.  <CODE>my_broken</CODE> can store an error
  622. message into <CODE>$error</CODE> this way.  Then the function that called
  623. <CODE>fill_in</CODE> can see if <CODE>my_broken</CODE> has left an error message for it
  624. to find, and proceed accordingly.</P>
  625. <P></P>
  626. <DT><STRONG><A NAME="item_SAFE"><CODE>SAFE</CODE></A></STRONG><BR>
  627. <DD>
  628. If you give <CODE>fill_in</CODE> a <A HREF="#item_SAFE"><CODE>SAFE</CODE></A> option, its value should be a safe
  629. compartment object from the <CODE>Safe</CODE> package.  All evaluation of
  630. program fragments will be performed in this compartment.  See <A HREF="../../../lib/Safe.html">the Safe manpage</A>
  631. for full details about such compartments and how to restrict the
  632. operations that can be performed in them.
  633. <P>If you use the <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A> option with <A HREF="#item_SAFE"><CODE>SAFE</CODE></A>, the package you specify
  634. will be placed into the safe compartment and evaluation will take
  635. place in that package as usual.</P>
  636. <P>If not, <A HREF="#item_SAFE"><CODE>SAFE</CODE></A> operation is a little different from the default.
  637. Usually, if you don't specify a package, evaluation of program
  638. fragments occurs in the package from which the template was invoked.
  639. But in <A HREF="#item_SAFE"><CODE>SAFE</CODE></A> mode the evaluation occurs inside the safe compartment
  640. and cannot affect the calling package.  Normally, if you use <A HREF="#item_HASH"><CODE>HASH</CODE></A>
  641. without <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A>, the hash variables are imported into a private,
  642. one-use-only package.  But if you use <A HREF="#item_HASH"><CODE>HASH</CODE></A> and <A HREF="#item_SAFE"><CODE>SAFE</CODE></A> together
  643. without <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A>, the hash variables will just be loaded into the
  644. root namespace of the <CODE>Safe</CODE> compartment.</P>
  645. <P></P>
  646. <DT><STRONG><A NAME="item_OUTPUT"><CODE>OUTPUT</CODE></A></STRONG><BR>
  647. <DD>
  648. If your template is going to generate a lot of text that you are just
  649. going to print out again anyway,  you can save memory by having
  650. <CODE>Text::Template</CODE> print out the text as it is generated instead of
  651. making it into a big string and returning the string.  If you supply
  652. the <A HREF="#item_OUTPUT"><CODE>OUTPUT</CODE></A> option to <CODE>fill_in</CODE>, the value should be a filehandle.
  653. The generated text will be printed to this filehandle as it is
  654. constructed.  For example:
  655. <PRE>
  656.         $template->fill_in(OUTPUT => \*STDOUT, ...);</PRE>
  657. <P>fills in the <CODE>$template</CODE> as usual, but the results are immediately
  658. printed to STDOUT.  This may result in the output appearing more
  659. quickly than it would have otherwise.</P>
  660. <P>If you use <A HREF="#item_OUTPUT"><CODE>OUTPUT</CODE></A>, the return value from <CODE>fill_in</CODE> is still true on
  661. success and false on failure, but the complete text is not returned to
  662. the caller.</P>
  663. <P></P>
  664. <DT><STRONG><A NAME="item_PREPEND"><CODE>PREPEND</CODE></A></STRONG><BR>
  665. <DD>
  666. You can have some Perl code prepended automatically to the beginning
  667. of every program fragment.  See <A HREF="#c<prepend> feature and using c<strict> in templates"><A HREF="#item_PREPEND"><CODE>PREPEND</CODE></A> feature and using <CODE>strict</CODE> in templates</A> below.
  668. <P></P>
  669. <DT><STRONG><CODE>DELIMITERS</CODE></STRONG><BR>
  670. <DD>
  671. If this option is present, its value should be a reference to a list
  672. of two strings.  The first string is the string that signals the
  673. beginning of each program fragment, and the second string is the
  674. string that signals the end of each program fragment.  See
  675. <A HREF="#alternative delimiters">Alternative Delimiters</A>, below.
  676. <P>If you specify <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A> in the call to <CODE>fill_in</CODE>, they override
  677. any delimiters you set when you created the template object with
  678. <CODE>new</CODE>.</P>
  679. <P></P></DL>
  680. <P>
  681. <HR>
  682. <H1><A NAME="convenience functions">Convenience Functions</A></H1>
  683. <P>
  684. <H2><A NAME="fill_this_in"><CODE>fill_this_in</CODE></A></H2>
  685. <P>The basic way to fill in a template is to create a template object and
  686. then call <CODE>fill_in</CODE> on it.   This is useful if you want to fill in
  687. the same template more than once.</P>
  688. <P>In some programs, this can be cumbersome.  <CODE>fill_this_in</CODE> accepts a
  689. string, which contains the template, and a list of options, which are
  690. passed to <CODE>fill_in</CODE> as above.  It constructs the template object for
  691. you, fills it in as specified, and returns the results.  It returns
  692. <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> and sets <CODE>$Text::Template::ERROR</CODE> if it couldn't generate
  693. any results.</P>
  694. <P>An example:</P>
  695. <PRE>
  696.         $Q::name = 'Donald';
  697.         $Q::amount = 141.61;
  698.         $Q::part = 'hyoid bone';</PRE>
  699. <PRE>
  700.         $text = Text::Template->fill_this_in( <<'EOM', PACKAGE => Q);
  701.         Dear {$name},
  702.         You owe me \\${sprintf('%.2f', $amount)}.  
  703.         Pay or I will break your {$part}.
  704.                 Love,
  705.                 Grand Vizopteryx of Irkutsk.
  706.         EOM</PRE>
  707. <P>Notice how we included the template in-line in the program by using a
  708. `here document' with the <CODE><<</CODE> notation.</P>
  709. <P><CODE>fill_this_in</CODE> is a deprecated feature.  It is only here for
  710. backwards compatibility, and may be removed in some far-future version
  711. in <CODE>Text::Template</CODE>.  You should use <CODE>fill_in_string</CODE> instead.  It
  712. is described in the next section.</P>
  713. <P>
  714. <H2><A NAME="fill_in_string"><CODE>fill_in_string</CODE></A></H2>
  715. <P>It is stupid that <CODE>fill_this_in</CODE> is a class method.  It should have
  716. been just an imported function, so that you could omit the
  717. <CODE>Text::Template-></CODE> in the example above.  But I made the mistake
  718. four years ago and it is too late to change it.</P>
  719. <P><CODE>fill_in_string</CODE> is exactly like <CODE>fill_this_in</CODE> except that it is
  720. not a method and you can omit the <CODE>Text::Template-></CODE> and just say</P>
  721. <PRE>
  722.         print fill_in_string(<<'EOM', ...);
  723.         Dear {$name},
  724.           ...
  725.         EOM</PRE>
  726. <P>To use <CODE>fill_in_string</CODE>, you need to say</P>
  727. <PRE>
  728.         use Text::Template 'fill_in_string';</PRE>
  729. <P>at the top of your program.   You should probably use
  730. <CODE>fill_in_string</CODE> instead of <CODE>fill_this_in</CODE>.</P>
  731. <P>
  732. <H2><A NAME="fill_in_file"><CODE>fill_in_file</CODE></A></H2>
  733. <P>If you import <CODE>fill_in_file</CODE>, you can say</P>
  734. <PRE>
  735.         $text = fill_in_file(filename, ...);</PRE>
  736. <P>The <CODE>...</CODE> are passed to <CODE>fill_in</CODE> as above.  The filename is the
  737. name of the file that contains the template you want to fill in.  It
  738. returns the result text. or <A HREF="../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A>, as usual.</P>
  739. <P>If you are going to fill in the same file more than once in the same
  740. program you should use the longer <CODE>new</CODE> / <CODE>fill_in</CODE> sequence instead.
  741. It will be a lot faster because it only has to read and parse the file
  742. once.</P>
  743. <P>
  744. <H2><A NAME="including files into templates">Including files into templates</A></H2>
  745. <P>People always ask for this.  ``Why don't you have an include
  746. function?'' they want to know.  The short answer is this is Perl, and
  747. Perl already has an include function.  If you want it, you can just put</P>
  748. <PRE>
  749.         {qx{cat filename}}</PRE>
  750. <P>into your template.  Voilà.</P>
  751. <P>If you don't want to use <CODE>cat</CODE>, you can write a little four-line
  752. function that opens a file and dumps out its contents, and call it
  753. from the template.  I wrote one for you.  In the template, you can say</P>
  754. <PRE>
  755.         {Text::Template::_load_text(filename)}</PRE>
  756. <P>If that is too verbose, here is a trick.  Suppose the template package
  757. that you are going to be mentioning in the <CODE>fill_in</CODE> call is package
  758. <CODE>Q</CODE>.  Then in the main program, write</P>
  759. <PRE>
  760.         *Q::include = \&Text::Template::_load_text;</PRE>
  761. <P>This imports the <CODE>_load_text</CODE> function into package <CODE>Q</CODE> with the
  762. name <CODE>include</CODE>.  From then on, any template that you fill in with
  763. package <CODE>Q</CODE> can say</P>
  764. <PRE>
  765.         {include(filename)}</PRE>
  766. <P>to insert the text from the named file at that point.  If you are
  767. using the <A HREF="#item_HASH"><CODE>HASH</CODE></A> option instead, just put <CODE>include =>
  768. \&Text::Template::_load_text</CODE> into the hash instead of importing it
  769. explicitly.</P>
  770. <P>Suppose you don't want to insert a plain text file, but rather you
  771. want to include one template within another?  Just use <CODE>fill_in_file</CODE>
  772. in the template itself:</P>
  773. <PRE>
  774.         {Text::Template::fill_in_file(filename)}</PRE>
  775. <P>You can do the same importing trick if this is too much to type.</P>
  776. <P>
  777. <HR>
  778. <H1><A NAME="miscellaneous">Miscellaneous</A></H1>
  779. <P>
  780. <H2><A NAME="my variables"><A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A> variables</A></H2>
  781. <P>People are frequently surprised when this doesn't work:</P>
  782. <PRE>
  783.         my $recipient = 'The King';
  784.         my $text = fill_in_file('formletter.tmpl');</PRE>
  785. <P>The text <CODE>The King</CODE> doesn't get into the form letter.  Why not?
  786. Because <CODE>$recipient</CODE> is a <A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A> variable, and the whole point of
  787. <A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A> variables is that they're private and inaccessible except in the
  788. scope in which they're declared.  The template is not part of that
  789. scope, so the template can't see <CODE>$recipient</CODE>.</P>
  790. <P>If that's not the behavior you want, don't use <A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A>.  <A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A> means a
  791. private variable, and in this case you don't want the variable to be
  792. private.  Put the variables into package variables in some other
  793. package, and use the <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A> option to <CODE>fill_in</CODE>:</P>
  794. <PRE>
  795.         $Q::recipient = $recipient;
  796.         my $text = fill_in_file('formletter.tmpl', PACKAGE => 'Q');</PRE>
  797. <P>or pass the names and values in a hash with the <A HREF="#item_HASH"><CODE>HASH</CODE></A> option:</P>
  798. <PRE>
  799.         my $text = fill_in_file('formletter.tmpl', HASH => { recipient => $recipient });</PRE>
  800. <P>
  801. <H2><A NAME="security matters">Security Matters</A></H2>
  802. <P>All variables are evaluated in the package you specify with the
  803. <A HREF="#item_PACKAGE"><CODE>PACKAGE</CODE></A> option of <CODE>fill_in</CODE>.  if you use this option, and if your
  804. templates don't do anything egregiously stupid, you won't have to
  805. worry that evaluation of the little programs will creep out into the
  806. rest of your program and wreck something.</P>
  807. <P>Nevertheless, there's really no way (except with <CODE>Safe</CODE>) to protect
  808. against a template that says</P>
  809. <PRE>
  810.         { $Important::Secret::Security::Enable = 0; 
  811.           # Disable security checks in this program 
  812.         }</PRE>
  813. <P>or</P>
  814. <PRE>
  815.         { $/ = "ho ho ho";   # Sabotage future uses of <FH>.
  816.           # $/ is always a global variable
  817.         }</PRE>
  818. <P>or even</P>
  819. <PRE>
  820.         { system("rm -rf /") }</PRE>
  821. <P>so <STRONG>don't</STRONG> go filling in templates unless you're sure you know what's
  822. in them.  If you're worried, or you can't trust the person who wrote
  823. the template, use the <A HREF="#item_SAFE"><CODE>SAFE</CODE></A> option.</P>
  824. <P>A final warning: program fragments run a small risk of accidentally
  825. clobbering local variables in the <CODE>fill_in</CODE> function itself.  These
  826. variables all have names that begin with <CODE>$fi_</CODE>, so if you stay away
  827. from those names you'll be safe.  (Of course, if you're a real wizard
  828. you can tamper with them deliberately for exciting effects; this is
  829. actually how <CODE>$OUT</CODE> works.)  I can fix this, but it will make the
  830. package slower to do it, so I would prefer not to.  If you are worried
  831. about this, send me mail and I will show you what to do about it.</P>
  832. <P>
  833. <H2><A NAME="alternative delimiters">Alternative Delimiters</A></H2>
  834. <P>Lorenzo Valdettaro pointed out that if you are using <CODE>Text::Template</CODE>
  835. to generate TeX output, the choice of braces as the program fragment
  836. delimiters makes you suffer suffer suffer.  Starting in version 1.20,
  837. you can change the choice of delimiters to something other than curly
  838. braces.</P>
  839. <P>In either the <CODE>new()</CODE> call or the <CODE>fill_in()</CODE> call, you can specify
  840. an alternative set of delimiters with the <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A> option.  For
  841. example, if you would like code fragments to be delimited by <CODE>[@--</CODE>
  842. and <CODE>--@]</CODE> instead of <CODE>{</CODE> and <CODE>}</CODE>, use</P>
  843. <PRE>
  844.         ... DELIMITERS =E<gt> [ '[@--', '--@]' ], ...</PRE>
  845. <P>Note that these delimiters are <EM>literal strings</EM>, not regexes.  (I
  846. tried for regexes, but it complicates the lexical analysis too much.)
  847. Note also that <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A> disables the special meaning of the
  848. backslash, so if you want to include the delimiters in the literal
  849. text of your template file, you are out of luck---it is up to you to
  850. choose delimiters that do not conflict with what you are doing.  The
  851. delimiter strings may still appear inside of program fragments as long
  852. as they nest properly.  This means that if for some reason you
  853. absolutely must have a program fragment that mentions one of the
  854. delimiters, like this:</P>
  855. <PRE>
  856.         [@--
  857.                 print "Oh no, a delimiter: --@]\n"
  858.         --@]</PRE>
  859. <P>you may be able to make it work by doing this instead:</P>
  860. <PRE>
  861.         [@--
  862.                 # Fake matching delimiter in a comment: [@--
  863.                 print "Oh no, a delimiter: --@]\n"
  864.         --@]</PRE>
  865. <P>It may be safer to choose delimiters that begin with a newline
  866. character.</P>
  867. <P>Because the parsing of templates is simplified by the absence of
  868. backslash escapes, using alternative <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A> <EM>speeds up</EM> the
  869. parsing process by 20-25%.  This shows that my original choice of <CODE>{</CODE>
  870. and <CODE>}</CODE> was very bad.  I therefore recommend that you use alternative
  871. delimiters whenever possible.</P>
  872. <P>
  873. <H2><A NAME="prepend feature and using strict in templates"><A HREF="#item_PREPEND"><CODE>PREPEND</CODE></A> feature and using <CODE>strict</CODE> in templates</A></H2>
  874. <P>Suppose you would like to use <CODE>strict</CODE> in your templates to detect
  875. undeclared variables and the like.  But each code fragment is a
  876. separate lexical scope, so you have to turn on <CODE>strict</CODE> at the top of
  877. each and every code fragment:</P>
  878. <PRE>
  879.         { use strict;
  880.           use vars '$foo';
  881.           $foo = 14;
  882.           ...
  883.         }</PRE>
  884. <PRE>
  885.         ...</PRE>
  886. <PRE>
  887.         { # we forgot to put `use strict' here
  888.           my $result = $boo + 12;    # $boo is misspelled and should be $foo
  889.           # No error is raised on `$boo'
  890.         }</PRE>
  891. <P>Because we didn't put <CODE>use strict</CODE> at the top of the second fragment,
  892. it was only active in the first fragment, and we didn't get any
  893. <CODE>strict</CODE> checking in the second fragment.  Then we mispelled <CODE>$foo</CODE>
  894. and the error wasn't caught.</P>
  895. <P><CODE>Text::Template</CODE> version 1.22 and higher has a new feature to make
  896. this easier.  You can specify that any text at all be automatically
  897. added to the beginning of each program fragment.</P>
  898. <P>When you make a call to <CODE>fill_in</CODE>, you can specify a</P>
  899. <PRE>
  900.         PREPEND => 'some perl statements here'</PRE>
  901. <P>option; the statements will be prepended to each program fragment for
  902. that one call only.  Suppose that the <CODE>fill_in</CODE> call included a</P>
  903. <PRE>
  904.         PREPEND => 'use strict;'</PRE>
  905. <P>option, and that the template looked like this:</P>
  906. <PRE>
  907.         { use vars '$foo';
  908.           $foo = 14;
  909.           ...
  910.         }</PRE>
  911. <PRE>
  912.         ...</PRE>
  913. <PRE>
  914.         { my $result = $boo + 12;    # $boo is misspelled and should be $foo
  915.           ...
  916.         }</PRE>
  917. <P>The code in the second fragment would fail, because <CODE>$boo</CODE> has not
  918. been declared.  <CODE>use strict</CODE> was implied, even though you did not
  919. write it explicitly, because the <A HREF="#item_PREPEND"><CODE>PREPEND</CODE></A> option added it for you
  920. automatically.</P>
  921. <P>There are two other ways to do this.  At the time you create the
  922. template object with <CODE>new</CODE>, you can also supply a <A HREF="#item_PREPEND"><CODE>PREPEND</CODE></A> option,
  923. in which case the statements will be prepended each time you fill in
  924. that template.  If the <CODE>fill_in</CODE> call has its own <A HREF="#item_PREPEND"><CODE>PREPEND</CODE></A> option,
  925. this overrides the one specified at the time you created the
  926. template.  Finally, you can make the class method call</P>
  927. <PRE>
  928.         Text::Template->always_prepend('perl statements');</PRE>
  929. <P>If you do this, then call calls to <CODE>fill_in</CODE> for <EM>any</EM> template will
  930. attach the perl statements to the beginning of each program fragment,
  931. except where overridden by <A HREF="#item_PREPEND"><CODE>PREPEND</CODE></A> options to <CODE>new</CODE> or <CODE>fill_in</CODE>.</P>
  932. <P>
  933. <H2><A NAME="prepending in derived classes">Prepending in Derived Classes</A></H2>
  934. <P>This section is technical, and you should skip it on the first few
  935. readings.</P>
  936. <P>Normally there are three places that prepended text could come from.
  937. It could come from the <A HREF="#item_PREPEND"><CODE>PREPEND</CODE></A> option in the <CODE>fill_in</CODE> call, from
  938. the <A HREF="#item_PREPEND"><CODE>PREPEND</CODE></A> option in the <CODE>new</CODE> call that created the template
  939. object, or from the argument of the <CODE>always_prepend</CODE> call.
  940. <CODE>Text::Template</CODE> looks for these three things in order and takes the
  941. first one that it finds.</P>
  942. <P>In a subclass of <CODE>Text::Template</CODE>, this last possibility is
  943. ambiguous.  Suppose <CODE>S</CODE> is a subclass of <CODE>Text::Template</CODE>.  Should</P>
  944. <PRE>
  945.         Text::Template->always_prepend(...);</PRE>
  946. <P>affect objects in class <CODE>Derived</CODE>?  The answer is that you can have it
  947. either way.</P>
  948. <P>The <CODE>always_prepend</CODE> value for <CODE>Text::Template</CODE> is normally stored
  949. in  a hash variable named <CODE>%GLOBAL_PREPEND</CODE> under the key
  950. <CODE>Text::Template</CODE>.  When <CODE>Text::Template</CODE> looks to see what text to
  951. prepend, it first looks in the template object itself, and if not, it
  952. looks in <CODE>$GLOBAL_PREPEND{class}</CODE> where <EM>class</EM> is the class to
  953. which the template object belongs.  If it doesn't find any value, it
  954. looks in <CODE>$GLOBAL_PREPEND{'Text::Template'}</CODE>.  This means that
  955. objects in class <CODE>Derived</CODE> <EM>will</EM> be affected by</P>
  956. <PRE>
  957.         Text::Template->always_prepend(...);</PRE>
  958. <P><EM>unless</EM> there is also a call to</P>
  959. <PRE>
  960.         Derived->always_prepend(...);</PRE>
  961. <P>So when you're designing your derived class, you can arrange to have
  962. your objects ignore <CODE>Text::Template::always_prepend</CODE> calls by simply
  963. putting <CODE>Derived->always_prepend('')</CODE> at the top of your module.</P>
  964. <P>Of course, there is also a final escape hatch: Templates support a
  965. <CODE>prepend_text</CODE> that is used to look up the appropriate text to be
  966. prepended at <CODE>fill_in</CODE> time.  Your derived class can override this
  967. method to get an arbitrary effect.</P>
  968. <P>
  969. <H2><A NAME="javascript">JavaScript</A></H2>
  970. <P>Jennifer D. St Clair asks:</P>
  971. <PRE>
  972.         > Most of my pages contain JavaScript and Stylesheets.
  973.         > How do I change the template identifier?</PRE>
  974. <P>Jennifer is worried about the braces in the JavaScript being taken as
  975. the delimiters of the Perl program fragments.  Of course, disaster
  976. will ensue when perl tries to evaluate these as if they were Perl
  977. programs.  The best choice is to find some unambiguous delimiter
  978. strings that you can use in your template instead of curly braces, and
  979. then use the <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A> option.  However, if you can't do this for
  980. some reason, there are  two easy workarounds:</P>
  981. <P>1. You can put <CODE>\</CODE> in front of <CODE>{</CODE>, <CODE>}</CODE>, or <CODE>\</CODE> to remove its
  982. special meaning.  So, for example, instead of</P>
  983. <PRE>
  984.             if (br== "n3") { 
  985.                 // etc.
  986.             }</PRE>
  987. <P>you can put</P>
  988. <PRE>
  989.             if (br== "n3") \{ 
  990.                 // etc.
  991.             \}</PRE>
  992. <P>and it'll come out of the template engine the way you want.</P>
  993. <P>But here is another method that is probably better.  To see how it
  994. works, first consider what happens if you put this into a template:</P>
  995. <PRE>
  996.             { 'foo' }</PRE>
  997. <P>Since it's in braces, it gets evaluated, and obviously, this is going
  998. to turn into</P>
  999. <PRE>
  1000.             foo</PRE>
  1001. <P>So now here's the trick: In Perl, <A HREF="../../../lib/Pod/perlfunc.html#item_q"><CODE>q{...}</CODE></A> is the same as <CODE>'...'</CODE>.
  1002. So if we wrote</P>
  1003. <PRE>
  1004.             {q{foo}}</PRE>
  1005. <P>it would turn into</P>
  1006. <PRE>
  1007.             foo</PRE>
  1008. <P>So for your JavaScript, just write</P>
  1009. <PRE>
  1010.             {q{
  1011.               if (br== "n3") { 
  1012.                   // etc.
  1013.               }
  1014.             }</PRE>
  1015. <P>and it'll come out as</P>
  1016. <PRE>
  1017.               if (br== "n3") { 
  1018.                   // etc.
  1019.               }</PRE>
  1020. <P>which is what you want.</P>
  1021. <P>
  1022. <H2><A NAME="shut up!">Shut Up!</A></H2>
  1023. <P>People sometimes try to put an initialization section at the top of
  1024. their templates, like this:</P>
  1025. <PRE>
  1026.         { ...
  1027.           $var = 17;
  1028.         }</PRE>
  1029. <P>Then they complain because there is a <CODE>17</CODE> at the top of the output
  1030. that they didn't want to have there.</P>
  1031. <P>Remember that a program fragment is replaced with its own return
  1032. value, and that in Perl the return value of a code block is the value
  1033. of the last expression that was evaluated, which in this case is 17.
  1034. If it didn't do that, you wouldn't be able to write <CODE>{$recipient}</CODE>
  1035. and have the recipient filled in.</P>
  1036. <P>To prevent the 17 from appearing in the output is very simple:</P>
  1037. <PRE>
  1038.         { ...
  1039.           $var = 17;
  1040.           '';
  1041.         }</PRE>
  1042. <P>Now the last expression evaluated yields the empty string, which is
  1043. invisible.  If you don't like the way this looks, use</P>
  1044. <PRE>
  1045.         { ...
  1046.           $var = 17;
  1047.           ($SILENTLY);
  1048.         }</PRE>
  1049. <P>instead.  Presumably, <CODE>$SILENTLY</CODE> has no value, so nothing will be
  1050. interpolated.  This is what is known as a `trick'.</P>
  1051. <P>
  1052. <H2><A NAME="compatibility">Compatibility</A></H2>
  1053. <P>Every effort has been made to make this module compatible with older
  1054. versions.  There are three exceptions.  One is the output format of
  1055. the default <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A> subroutine; I decided that the old format was
  1056. too verbose.  If this bothers you, it's easy to supply a custom
  1057. subroutine that yields the old behavior.  The second is that the
  1058. <CODE>$OUT</CODE> feature arrogates the <CODE>$OUT</CODE> variable for itself.  If you had
  1059. templates that happened to use a variable named <CODE>$OUT</CODE>, you will have
  1060. to change them to use some other variable or all sorts of strangeness
  1061. may result.</P>
  1062. <P>The third incompatibility is with the behavior of the \ metacharacter.
  1063. In 0.1b, \\ was special everywhere, and the template processor always
  1064. replaced it with a single backslash before passing the code to Perl
  1065. for evaluation.  The rule now is more complicated but probably more
  1066. convenient.  See the section on backslash processing, below, for a
  1067. full discussion.</P>
  1068. <P>With a minor change to fix the format of the default <A HREF="#item_BROKEN"><CODE>BROKEN</CODE></A>
  1069. subroutine, this version passes the test suite from the old version.
  1070. (It is in <CODE>t/01-basic.t</CODE>.) The old test suite was too small, but it's
  1071. a little reassuring.</P>
  1072. <P>
  1073. <H2><A NAME="backslash processing">Backslash Processing</A></H2>
  1074. <P>In <CODE>Text::Template</CODE> beta versions, the backslash was special whenever
  1075. it appeared before a brace or another backslash.  That meant that
  1076. while <CODE>{"\n"}</CODE> did indeed generate a newline, <CODE>{"\\"}</CODE> did not
  1077. generate a backslash, because the code passed to Perl for evaluation
  1078. was <CODE>"\"</CODE> which is a syntax error.  If you wanted a backslash, you
  1079. would have had to write <CODE>{"\\\\"}</CODE>.</P>
  1080. <P>In <CODE>Text::Template</CODE> versions 1.0 through 1.10, there was a bug:
  1081. Backslash was special everywhere.  In these versions, <CODE>{"\n"}</CODE>
  1082. generated the letter <CODE>n</CODE>.</P>
  1083. <P>The bug has been corrected in version 1.11, but I did not go back to
  1084. exactly the old rule, because I did not like the idea of having to
  1085. write <CODE>{"\\\\"}</CODE> to get one backslash.  The rule is now more
  1086. complicated to remember, but probably easier to use.  The rule is now:
  1087. Backslashes are always passed to Perl unchanged <EM>unless</EM> they occur
  1088. as part of a sequence like <CODE>\\\\\\{</CODE> or <CODE>\\\\\\}</CODE>.  In these
  1089. contexts, they are special; <CODE>\\</CODE> is replaced with <CODE>\</CODE>, and <CODE>\{</CODE> and
  1090. <CODE>\}</CODE> signal a literal brace.</P>
  1091. <P>Examples:</P>
  1092. <PRE>
  1093.         \{ foo \}</PRE>
  1094. <P>is <EM>not</EM> evaluated, because the <CODE>\</CODE> before the braces signals that
  1095. they should be taken literally.  The result in the output looks like this:</P>
  1096. <PRE>
  1097.         { foo }</PRE>
  1098. <P>This is a syntax error:</P>
  1099. <PRE>
  1100.         { "foo}" }</PRE>
  1101. <P>because <CODE>Text::Template</CODE> thinks that the code ends at the first <CODE>}</CODE>,
  1102. and then gets upset when it sees the second one.  To make this work
  1103. correctly, use</P>
  1104. <PRE>
  1105.         { "foo\}" }</PRE>
  1106. <P>This passes <CODE>"foo}"</CODE> to Perl for evaluation.  Note there's no <CODE>\</CODE> in
  1107. the evaluated code.  If you really want a <CODE>\</CODE> in the evaluated code,
  1108. use</P>
  1109. <PRE>
  1110.         { "foo\\\}" }</PRE>
  1111. <P>This passes <CODE>"foo\}"</CODE> to Perl for evaluation.</P>
  1112. <P>Starting with <CODE>Text::Template</CODE> version 1.20, backslash processing is
  1113. disabled if you use the <A HREF="#item_DELIMITERS"><CODE>DELIMITERS</CODE></A> option to specify alternative
  1114. delimiter strings.</P>
  1115. <P>
  1116. <H2><A NAME="a short note about $text::template::error">A short note about <CODE>$Text::Template::ERROR</CODE></A></H2>
  1117. <P>In the past some people have fretted about `violating the package
  1118. boundary' by examining a variable inside the <CODE>Text::Template</CODE>
  1119. package.  Don't feel this way.  <CODE>$Text::Template::ERROR</CODE> is part of
  1120. the published, official interface to this package.  It is perfectly OK
  1121. to inspect this variable.  The interface is not going to change.</P>
  1122. <P>If it really, really bothers you, you can import a function called
  1123. <CODE>TTerror</CODE> that returns the current value of the <CODE>$ERROR</CODE> variable.
  1124. So you can say:</P>
  1125. <PRE>
  1126.         use Text::Template 'TTerror';</PRE>
  1127. <PRE>
  1128.         my $template = new Text::Template (SOURCE => $filename);
  1129.         unless ($template) {
  1130.           my $err = TTerror;
  1131.           die "Couldn't make template: $err; aborting";
  1132.         }</PRE>
  1133. <P>I don't see what benefit this has over just doing this:</P>
  1134. <PRE>
  1135.         use Text::Template;</PRE>
  1136. <PRE>
  1137.         my $template = new Text::Template (SOURCE => $filename)
  1138.           or die "Couldn't make template: $Text::Template::ERROR; aborting";</PRE>
  1139. <P>But if it makes you happy to do it that way, go ahead.</P>
  1140. <P>
  1141. <H2><A NAME="sticky widgets in template files">Sticky Widgets in Template Files</A></H2>
  1142. <P>The <CODE>CGI</CODE> module provides functions for `sticky widgets', which are
  1143. form input controls that retain their values from one page to the
  1144. next.   Sometimes people want to know how to include these widgets
  1145. into their template output.</P>
  1146. <P>It's totally straightforward.  Just call the <CODE>CGI</CODE> functions from
  1147. inside the template:</P>
  1148. <PRE>
  1149.         { $q->checkbox_group(NAME => 'toppings',
  1150.                              LINEBREAK => true,
  1151.                              COLUMNS => 3,
  1152.                              VALUES => \@toppings,
  1153.                             );
  1154.         }</PRE>
  1155. <P>
  1156. <H2><A NAME="author">Author</A></H2>
  1157. <P>Mark-Jason Dominus, Plover Systems</P>
  1158. <P>Please send questions and other remarks about this software to
  1159. <CODE>mjd-perl-template@pobox.com</CODE></P>
  1160. <P>You can join a very low-volume (<10 messages per year) mailing
  1161. list for announcements about this package.  Send an empty note to
  1162. <CODE>mjd-perl-template-request@plover.com</CODE> to join.</P>
  1163. <P>For updates, visit <CODE>http://www.plover.com/~mjd/perl/Template/</CODE>.</P>
  1164. <P>
  1165. <H2><A NAME="support">Support?</A></H2>
  1166. <P>This software is version 1.0.  It is a complete rewrite of an older
  1167. package, and may have bugs.  Suggestions and bug reports are always
  1168. welcome.  Send them to <CODE>mjd-perl-template@plover.com</CODE>.  (That is my
  1169. address, not the address of the mailing list.  The mailing list
  1170. address is a secret.)</P>
  1171. <P>
  1172. <H2><A NAME="thanks">Thanks</A></H2>
  1173. <P>Many thanks to the following people for offering support,
  1174. encouragement, advice, and all the other good stuff.</P>
  1175. <P>Klaus Arnhold /
  1176. Chris.Brezil /
  1177. Mike Brodhead /
  1178. Tom Brown /
  1179. Tim Bunce /
  1180. Juan E. Camacho /
  1181. Joseph Cheek /
  1182. San Deng /
  1183. Bob Dougherty /
  1184. Dan Franklin /
  1185. Todd A. Green /
  1186. Michelangelo Grigni /
  1187. Tom Henry /
  1188. Matt X. Hunter /
  1189. Robert M. Ioffe /
  1190. Daniel LaLiberte /
  1191. Reuven M. Lerner /
  1192. Joel Meulenberg /
  1193. Jason Moore /
  1194. Bek Oberin /
  1195. Ron Pero /
  1196. Hans Persson /
  1197. Jonathan Roy /
  1198. Shabbir J. Safdar /
  1199. Jennifer D. St Clair /
  1200. Uwe Schneider /
  1201. Randal L. Schwartz /
  1202. Michael G Schwern /
  1203. Brian C. Shensky /
  1204. Niklas Skoglund /
  1205. Tom Snee /
  1206. Hans Stoop /
  1207. Michael J. Suzio /
  1208. Dennis Taylor /
  1209. James H. Thompson /
  1210. Shad Todd /
  1211. Lorenzo Valdettaro /
  1212. Larry Virden /
  1213. Andy Wardley /
  1214. Matt Womer /
  1215. Andrew G Wood /
  1216. Michaely Yeung</P>
  1217. <P>Special thanks to:</P>
  1218. <DL>
  1219. <DT><STRONG><A NAME="item_Jonathan_Roy">Jonathan Roy</A></STRONG><BR>
  1220. <DD>
  1221. for telling me how to do the <CODE>Safe</CODE> support (I spent two years
  1222. worrying about it, and then Jonathan pointed out that it was trivial.)
  1223. <P></P>
  1224. <DT><STRONG><A NAME="item_Ranjit_Bhatnagar">Ranjit Bhatnagar</A></STRONG><BR>
  1225. <DD>
  1226. for demanding less verbose fragments like they have in ASP, for
  1227. helping me figure out the Right Thing, and, especially, for talking me
  1228. out of adding any new syntax.  These discussions resulted in the
  1229. <CODE>$OUT</CODE> feature.
  1230. <P></P>
  1231. <DT><STRONG><A NAME="item_Shabbir_J%2E_Safdar">Shabbir J. Safdar</A></STRONG><BR>
  1232. <DD>
  1233. for volunteering to maintain a slightly modified version of
  1234. <CODE>Text::Template</CODE> which will run under perl.5003 and other early
  1235. versions.
  1236. <P></P></DL>
  1237. <P>
  1238. <H2><A NAME="bugs and caveats">Bugs and Caveats</A></H2>
  1239. <P><A HREF="../../../lib/Pod/perlfunc.html#item_my"><CODE>my</CODE></A> variables in <CODE>fill_in</CODE> are still susceptible to being clobbered
  1240. by template evaluation.  They all begin with <CODE>fi_</CODE>, so avoid those
  1241. names in your templates.</P>
  1242. <P>The line number information will be wrong if the template's lines are
  1243. not terminated by <CODE>"\n"</CODE>.  You should let me know if this is a
  1244. problem.  If you do, I will fix it.</P>
  1245. <P>The default format for reporting of broken program fragments has
  1246. changed since version 0.1.</P>
  1247. <P>The <CODE>$OUT</CODE> variable has a special meaning in templates, so you cannot
  1248. use it as if it were a regular variable.</P>
  1249. <P>There are not quite enough tests in the test suite.</P>
  1250. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  1251. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  1252. <STRONG><P CLASS=block> Text::Template - Expand template text with embedded Perl</P></STRONG>
  1253. </TD></TR>
  1254. </TABLE>
  1255.  
  1256. </BODY>
  1257.  
  1258. </HTML>
  1259.