Text::Template v1.23
This is a library for generating form letters, building HTML pages, or
filling in templates generally. A `template' is a piece of text that
has little Perl programs embedded in it here and there. When you
`fill in' a template, you evaluate the little programs and replace
them with their values.
Here's an example of a template:
Dear {$title} {$lastname},
It has come to our attention that you are delinquent in your
{$monthname[$last_paid_month]} payment. Please remit
${sprintf("%.2f", $amount)} immediately, or your patellae may
be needlessly endangered.
Love,
Mark "{nickname(rand 20)}" Dominus
The result of filling in this template is a string, which might look
something like this:
Dear Mr. Gates,
It has come to our attention that you are delinquent in your
February payment. Please remit
$392.12 immediately, or your patellae may
be needlessly endangered.
Love,
Mark "Vizopteryx" Dominus
You can store a template in a file outside your program. People can
modify the template without modifying the program. You can separate
the formatting details from the main code, and put the formatting
parts of the program into the template. That prevents code bloat and
encourages functional separation.
You can fill in the template in a `Safe' compartment. This means tat
if you don't trust the person who wrote the code in the template, you
won't have to worry that they are tampering with your program when you
execute it.
----------------------------------------------------------------
Text::Template was originally released some time in late 1995 or early
1996. After three years of study and investigation, I rewrote it from
scratch in January 1999. The new version, 1.0, was much faster,
delivered better functionality and was almost 100% backward-compatible
with the previous beta versions.
I have added a number of useful features and conveniences since the
1.0 release, while still retaining backward compatibility. With one
merely cosmetic change, the current version of Text::Template passes
the test suite that the old beta versions passed.
Questions or comments should be addressed to
mjd-perl-template@plover.com. This address goes directly to me, and
not to anyone else; it is not a mailing list address.
To receive occasional announcements of new versions of T::T, send an
empty note to mjd-perl-template-request@plover.com. This mailing list
is not for discussion; it is for announcements only. Therefore, there
is no address for sending messages to the list.
You can get the most recent version of Text::Template, news, comments,
and other collateral information from
.
----------------------------------------------------------------
What's new in v1.223since v1.22:
Small bug fix: DELIMITER and other arguments were being
ignored in calls to fill_in_file and fill_this_in. (Thanks to
Jonathan Roy.)
----------------------------------------------------------------
What's new in v1.22 since v1.20:
You can now specify that certain Perl statements be prepended
to the beginning of every program fragment in a template,
either per template, or for all templates, or for the duration
of only one call to fill_in. This is useful, for example, if
you want to enable `strict' checks in your templates but you
don't want to manually add `use strict' to the front of every
program fragment everywhere.
----------------------------------------------------------------
What's new in v1.20 since v1.12:
You can now specify that the program fragment delimiters are
strings other than { and }. This has three interesting
effects: First, it changes the delimiter strings. Second, it
disables the special meaning of \, so you have to be really,
really sure that the delimiters will not appear in your
templates. And third, because of the simplifications
introduced by the elimination of \ processing, template
parsing is 20-25% faster.
See the manual section on `Alternative Delimiters'.
Fixed bug having to do with undefined values in HASH options.
In particular, Text::Template no longer generates a warning if
you try to give a variable an undefined value.
----------------------------------------------------------------
What's new in v1.12 since v1.11:
I forgot to say that Text::Template ISA Exporter, so the
exported functions never got exported. Duhhh!
Template TYPEs are now case-insensitive. The `new' method now
diagnoses attempts to use an invalid TYPE.
More tests for these things.
----------------------------------------------------------------
What's new in v1.11 since v1.10:
Fixed a bug in the way backslashes were processed. The 1.10
behavior was incompatible with the beta versions and was also
inconvenient. (`\n' in templates was replaced with `n' before
it was given to Perl for evaluation.) The new behavior is
also incompatible with the beta versions, but it is only a
little bit incompatible, and it is probbaly better.
Documentation for the new behavior, and tests for the bug.
----------------------------------------------------------------
What's new in v1.10 since v1.03:
New OUTPUT option delivers template results directly to a
filehandle instead of making them into a string. Saves space
and time.
PACKAGE and HASH now work intelligently with SAFE.
Fragments may now output data directly to the template, rather
than having to arrange to return it as a return value at the
end. This means that where you used to have to write this:
{ my $blist = '';
foreach $i (@items) {
$blist .= qq{ * $i\n};
}
$blist;
}
You can now write this instead, because $OUT is special.
{ foreach $i (@items) {
$OUT.= " * $i\n";
}
}
(`A spoonful of sugar makes the medicine go down.')
Fixed some small bugs. Worked around a bug in Perl that does
the wrong thing with $x = when $x contains a glob.
More documentation. Errors fixed.
Lots more tests.
----------------------------------------------------------------
What's new in v1.03 since v1.0:
Code added to support HASH option to fill_in.
(Incl. `_gensym' function.)
Documentation for HASH.
New test file for HASH.
Note about failure of lexical variables to propagate into
templates. Why does this surprise people?
Bug fix: program fragments are evaluated in an environment with
`no strict' by default. Otherwise, you get a lot of `Global
symbol "$v" requires explicit package name' failures. Why didn't
the test program pick this up? Because the only variable the test
program ever used was `$a', which is exempt. Duhhhhh.
Fixed the test program.
Various minor documentation fixes.
----------------------------------------------------------------
Improvements of 1.0 over the old 0.1beta:
New features:
At least twice as fast
Better support for filling out the same template more than once
Now supports evaluation of program fragments in Safe
compartments. (Thanks, Jonathan!)
Better argument syntax
More convenience functions
The parser is much better and simpler.
Once a template is parsed, the parsed version is stored so that
it needn't be parsed again.
BROKEN function behavior is rationalized. You can now pass an
arbitrary argument to your BROKEN function, or return a value
from it to the main program.
Documentation overhauled.