README 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. Text::Template v1.46
  2. This is a library for generating form letters, building HTML pages, or
  3. filling in templates generally. A `template' is a piece of text that
  4. has little Perl programs embedded in it here and there. When you
  5. `fill in' a template, you evaluate the little programs and replace
  6. them with their values.
  7. Here's an example of a template:
  8. Dear {$title} {$lastname},
  9. It has come to our attention that you are delinquent in your
  10. {$monthname[$last_paid_month]} payment. Please remit
  11. ${sprintf("%.2f", $amount)} immediately, or your patellae may
  12. be needlessly endangered.
  13. Love,
  14. Mark "{nickname(rand 20)}" Dominus
  15. The result of filling in this template is a string, which might look
  16. something like this:
  17. Dear Mr. Gates,
  18. It has come to our attention that you are delinquent in your
  19. February payment. Please remit
  20. $392.12 immediately, or your patellae may
  21. be needlessly endangered.
  22. Love,
  23. Mark "Vizopteryx" Dominus
  24. You can store a template in a file outside your program. People can
  25. modify the template without modifying the program. You can separate
  26. the formatting details from the main code, and put the formatting
  27. parts of the program into the template. That prevents code bloat and
  28. encourages functional separation.
  29. You can fill in the template in a `Safe' compartment. This means that
  30. if you don't trust the person who wrote the code in the template, you
  31. won't have to worry that they are tampering with your program when you
  32. execute it.
  33. ----------------------------------------------------------------
  34. Text::Template was originally released some time in late 1995 or early
  35. 1996. After three years of study and investigation, I rewrote it from
  36. scratch in January 1999. The new version, 1.0, was much faster,
  37. delivered better functionality and was almost 100% backward-compatible
  38. with the previous beta versions.
  39. I have added a number of useful features and conveniences since the
  40. 1.0 release, while still retaining backward compatibility. With one
  41. merely cosmetic change, the current version of Text::Template passes
  42. the test suite that the old beta versions passed.
  43. Questions or comments should be addressed to
  44. mjd-perl-template+@plover.com. This address goes directly to me, and
  45. not to anyone else; it is not a mailing list address.
  46. To receive occasional announcements of new versions of T::T, send an
  47. empty note to mjd-perl-template-request@plover.com. This mailing list
  48. is not for discussion; it is for announcements only. Therefore, there
  49. is no address for sending messages to the list.
  50. You can get the most recent version of Text::Template, news, comments,
  51. and other collateral information from
  52. <URL:http://www.plover.com/~mjd/perl/Template/>.
  53. ----------------------------------------------------------------
  54. What's new in v1.46 since v1.44:
  55. Thanks to Rik Signes, there is a new
  56. Text::Template->append_text_to_output method, which
  57. Text::Template always uses whenever it wants to emit output.
  58. You can subclass this to get control over the output, for
  59. example for postprocessing.
  60. A spurious warning is no longer emitted when the TYPE
  61. parameter to ->new is omitted.
  62. ----------------------------------------------------------------
  63. What's new in v1.44 since v1.43:
  64. This is a maintentance release. There are no feature changes.
  65. _scrubpkg, which was responsible for eptying out temporary
  66. packages after the module had done with them, wasn't always
  67. working; the result was memory-leaks in long-running
  68. applications. This should be fixed now, and there is a test
  69. in the test suite for it.
  70. Minor changes to the test suite to prevent spurious errors.
  71. Minor documentation changes.
  72. ----------------------------------------------------------------
  73. What's new in v1.43 since v1.42:
  74. The ->new method now fails immediately and sets
  75. $Text::Template::ERROR if the file that is named by a filename
  76. argument does not exist or cannot be opened for some other
  77. reason. Formerly, the constructor would succeed and the
  78. ->fill_in call would fail.
  79. ----------------------------------------------------------------
  80. What's new in v1.42 since v1.41:
  81. This is a maintentance release. There are no feature changes.
  82. Fixed a bug relating to use of UNTAINT under perl 5.005_03 and
  83. possibly other versions.
  84. Taint-related tests are now more comprehensive.
  85. ----------------------------------------------------------------
  86. What's new in v1.41 since v1.40:
  87. This is a maintentance release. There are no feature changes.
  88. Tests now work correctly on Windows systems and possibly on
  89. other non-unix systems.
  90. ----------------------------------------------------------------
  91. What's new in v1.40 since v1.31:
  92. New UNTAINT option tells the module that it is safe to 'eval'
  93. code even though it has come from a file or filehandle.
  94. Code added to prevent memory leaks when filling many
  95. templates. Thanks to Itamar Almeida de Carvalho.
  96. Bug fix: $OUT was not correctly initialized when used in
  97. conjunction with SAFE.
  98. You may now use a glob ref when passing a filehandle to the
  99. ->new funcion. Formerly, a glob was reuqired.
  100. New subclass: Text::Template::Preprocess. Just like
  101. Text::Template, but you may supply a PREPROCESS option in the
  102. constructor or the fill_in call; this is a function which
  103. receives each code fragment prior to evaluation, and which may
  104. modify and return the fragment; the modified fragment is what
  105. is evaluated.
  106. Error messages passed to BROKEN subroutines will now report
  107. the correct line number of the template at which the error
  108. occurred:
  109. Illegal division by zero at template line 37.
  110. If the template comes from a file, the filename will be
  111. reported as well:
  112. Illegal division by zero at catalog.tmpl line 37.
  113. INCOMPATIBLE CHANGE:
  114. The format of the default error message has changed. It used
  115. to look like:
  116. Program fragment at line 30 delivered error ``Illegal division by zero''
  117. It now looks like:
  118. Program fragment delivered error ``Illegal division by zero at catalog.tmpl line 37''
  119. Note that the default message used to report the line number
  120. at which the program fragment began; it now reports the line
  121. number at which the error actually occurred.
  122. ----------------------------------------------------------------
  123. What's new in v1.31 since v1.23:
  124. Just bug fixes---fill_in_string was failing. Thanks to
  125. Donald L. Greer Jr. for the test case.
  126. ----------------------------------------------------------------
  127. What's new in v1.23 since v1.22:
  128. Small bug fix: DELIMITER and other arguments were being
  129. ignored in calls to fill_in_file and fill_this_in. (Thanks to
  130. Jonathan Roy for reporting this.)
  131. ----------------------------------------------------------------
  132. What's new in v1.22 since v1.20:
  133. You can now specify that certain Perl statements be prepended
  134. to the beginning of every program fragment in a template,
  135. either per template, or for all templates, or for the duration
  136. of only one call to fill_in. This is useful, for example, if
  137. you want to enable `strict' checks in your templates but you
  138. don't want to manually add `use strict' to the front of every
  139. program fragment everywhere.
  140. ----------------------------------------------------------------
  141. What's new in v1.20 since v1.12:
  142. You can now specify that the program fragment delimiters are
  143. strings other than { and }. This has three interesting
  144. effects: First, it changes the delimiter strings. Second, it
  145. disables the special meaning of \, so you have to be really,
  146. really sure that the delimiters will not appear in your
  147. templates. And third, because of the simplifications
  148. introduced by the elimination of \ processing, template
  149. parsing is 20-25% faster.
  150. See the manual section on `Alternative Delimiters'.
  151. Fixed bug having to do with undefined values in HASH options.
  152. In particular, Text::Template no longer generates a warning if
  153. you try to give a variable an undefined value.
  154. ----------------------------------------------------------------
  155. What's new in v1.12 since v1.11:
  156. I forgot to say that Text::Template ISA Exporter, so the
  157. exported functions never got exported. Duhhh!
  158. Template TYPEs are now case-insensitive. The `new' method now
  159. diagnoses attempts to use an invalid TYPE.
  160. More tests for these things.
  161. ----------------------------------------------------------------
  162. What's new in v1.11 since v1.10:
  163. Fixed a bug in the way backslashes were processed. The 1.10
  164. behavior was incompatible with the beta versions and was also
  165. inconvenient. (`\n' in templates was replaced with `n' before
  166. it was given to Perl for evaluation.) The new behavior is
  167. also incompatible with the beta versions, but it is only a
  168. little bit incompatible, and it is probbaly better.
  169. Documentation for the new behavior, and tests for the bug.
  170. ----------------------------------------------------------------
  171. What's new in v1.10 since v1.03:
  172. New OUTPUT option delivers template results directly to a
  173. filehandle instead of making them into a string. Saves space
  174. and time.
  175. PACKAGE and HASH now work intelligently with SAFE.
  176. Fragments may now output data directly to the template, rather
  177. than having to arrange to return it as a return value at the
  178. end. This means that where you used to have to write this:
  179. { my $blist = '';
  180. foreach $i (@items) {
  181. $blist .= qq{ * $i\n};
  182. }
  183. $blist;
  184. }
  185. You can now write this instead, because $OUT is special.
  186. { foreach $i (@items) {
  187. $OUT.= " * $i\n";
  188. }
  189. }
  190. (`A spoonful of sugar makes the medicine go down.')
  191. Fixed some small bugs. Worked around a bug in Perl that does
  192. the wrong thing with $x = <Y> when $x contains a glob.
  193. More documentation. Errors fixed.
  194. Lots more tests.
  195. ----------------------------------------------------------------
  196. What's new in v1.03 since v1.0:
  197. Code added to support HASH option to fill_in.
  198. (Incl. `_gensym' function.)
  199. Documentation for HASH.
  200. New test file for HASH.
  201. Note about failure of lexical variables to propagate into
  202. templates. Why does this surprise people?
  203. Bug fix: program fragments are evaluated in an environment with
  204. `no strict' by default. Otherwise, you get a lot of `Global
  205. symbol "$v" requires explicit package name' failures. Why didn't
  206. the test program pick this up? Because the only variable the test
  207. program ever used was `$a', which is exempt. Duhhhhh.
  208. Fixed the test program.
  209. Various minor documentation fixes.
  210. ----------------------------------------------------------------
  211. Improvements of 1.0 over the old 0.1beta:
  212. New features:
  213. At least twice as fast
  214. Better support for filling out the same template more than once
  215. Now supports evaluation of program fragments in Safe
  216. compartments. (Thanks, Jonathan!)
  217. Better argument syntax
  218. More convenience functions
  219. The parser is much better and simpler.
  220. Once a template is parsed, the parsed version is stored so that
  221. it needn't be parsed again.
  222. BROKEN function behavior is rationalized. You can now pass an
  223. arbitrary argument to your BROKEN function, or return a value
  224. from it to the main program.
  225. Documentation overhauled.