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