In this chapter, we've looked at a few of the available templating tools that are commonly used in Perl; from simple formats--sprintf, and the like--on through Text::Template and HTML::Template, and then up to the more sophisticated solutions of HTML::Mason and Template Toolkit.
But we've missed out on one quite important question: which one should you use? As usual, the answer depends partly on what you need and partly on your tastes.
First, consider the distinction between Perl-based systems like Text::Template and Text::Autoformat, and inside-out modules like HTML::Mason. If the main purpose of your program is to provide some templated output, as in the case of a web-based application, then you probably want to gravitate toward the HTML::Mason and Template Toolkit end of the spectrum.
You also need to consider who's going to be writing the templates and whether you want to expose them to Perl code. Template Toolkit, AxKit, and HTML::Template all tend to keep the templater away from Perl, whereas HTML::Mason forces the templater to get down and dirty with it.
Second, there's the element of personal taste. I'm not a great fan of HTML::Template, preferring the way Mason does things; I find AxKit very powerful but at times very frustrating because of its insistence on clean XML; and I'm beginning to like Template Toolkit the more I use it, but prefer Mason basically because I'm more used to it.
Your tastes may differ. It's just as well, that as with so many things in Perl, there's more than one way to do it.
* As it happens, I didnít actually use formats in my code, because I wanted to have a variable-width instead of a fixed-width display. But for cases where a fixed-width output is acceptable, this solution is perfect.
* Allowing a user-defined argument is a great way to make a callback extremely extensible.
* Feel free, of course, to implement all these things as an exercise in HTML::Mason programming.
* If you need the actual Apache request object in Mason, itís available as $r.
* Therefore, as it happens, all requests will go through index.html, and we could have put our header and footer code in there, but using an autohandler is cleaner and actually more conventional.
* And probably no desire to find out!
* We completely glossed over this in the Text::Template example; did you notice?