| 1 |
|
| 2 |
Text::Template |
| 3 |
|
| 4 |
This is a library for generating form letters, building HTML pages, or |
| 5 |
filling in templates generally. A `template' is a piece of text that |
| 6 |
has little Perl programs embedded in it here and there. When you |
| 7 |
`fill in' a template, you evaluate the little programs and replace |
| 8 |
them with their values. |
| 9 |
|
| 10 |
Here's an example of a template: |
| 11 |
|
| 12 |
Dear {$title} {$lastname}, |
| 13 |
|
| 14 |
It has come to our attention that you are delinquent in your |
| 15 |
{$monthname[$last_paid_month]} payment. Please remit |
| 16 |
${sprintf("%.2f", $amount)} immediately, or your patellae may |
| 17 |
be needlessly endangered. |
| 18 |
|
| 19 |
Love, |
| 20 |
|
| 21 |
Mark "{nickname(rand 20)}" Dominus |
| 22 |
|
| 23 |
|
| 24 |
The result of filling in this template is a string, which might look |
| 25 |
something like this: |
| 26 |
|
| 27 |
Dear Mr. Gates, |
| 28 |
|
| 29 |
It has come to our attention that you are delinquent in your |
| 30 |
February payment. Please remit |
| 31 |
$392.12 immediately, or your patellae may |
| 32 |
be needlessly endangered. |
| 33 |
|
| 34 |
|
| 35 |
Love, |
| 36 |
|
| 37 |
Mark "Vizopteryx" Dominus |
| 38 |
|
| 39 |
You can store a template in a file outside your program. People can |
| 40 |
modify the template without modifying the program. You can separate |
| 41 |
the formatting details from the main code, and put the formatting |
| 42 |
parts of the program into the template. That prevents code bloat and |
| 43 |
encourages functional separation. |
| 44 |
|
| 45 |
You can fill in the template in a `Safe' compartment. This means that |
| 46 |
if you don't trust the person who wrote the code in the template, you |
| 47 |
won't have to worry that they are tampering with your program when you |
| 48 |
execute it. |
| 49 |
|
| 50 |
---------------------------------------------------------------- |
| 51 |
|
| 52 |
Text::Template was originally released some time in late 1995 or early |
| 53 |
1996. After three years of study and investigation, I rewrote it from |
| 54 |
scratch in January 1999. The new version, 1.0, was much faster, |
| 55 |
delivered better functionality and was almost 100% backward-compatible |
| 56 |
with the previous beta versions. |
| 57 |
|
| 58 |
I have added a number of useful features and conveniences since the |
| 59 |
1.0 release, while still retaining backward compatibility. With one |
| 60 |
merely cosmetic change, the current version of Text::Template passes |
| 61 |
the test suite that the old beta versions passed. |
| 62 |
|