The Perl Journal March, 2004
Perl Template Toolkit
Darren Chamberlain, David Cross, and Andy Wardley
O'Reilly and Associates, 2004
592 pp., $39.95
ISBN 0-596-00476-1
Perl Template Toolkit coauthor Andy Wardley is the developer of the Template Toolkit, a Perl library providing for embedding textual substitution and live Perl code in text documents and text fragments. The template idea has been seen before in Perl, in a variety of CPAN offerings. The Template Toolkit emerged as an admixture and distillation of extant ideas into a framework with a variety of capabilities, ranging from those equivalent to m4 macro preprocessing, to inline code execution and database access facilities equivalent to those provided in Java by Java Server Pages or by the attractive-but-foundering-in-the-marketplace NET.DATA from IBM.
From a computer-science viewpoint, what we have in Perl templates is one of those simple ideas that can be folded over on itself fractally, lavishly, and almost infinitely. Furthermore, the ease of Template Toolkit development in Perl compares favorably with the numbing weight and complexity of real-world Java JSP development. The template idea, though applicable to a wide range of tasks, is, like much of Perl itself, aimed primarily at the generation of web pages. Perl Template Toolkit starts from generation of static documents, works its way through dynamic web pages, plugins, database access, XML, and even discusses modifying the Template Toolkit itself.
Perl Template Toolkit is a really good book. The Template Toolkit is one of those ideas whose time has come, the authors are as expert as expert can be, and the book itself is a quality production. I can find few faultsone certainly is sanguinity about the complexity of what is being conveyed. The audience for Perl Template Toolkit is proclaimed to be:
"...anyone building and maintaining web sites or other complex content systems. No prior knowledge of Perl, the Template Toolkit, or HTML is required to apply the basic techniques taught in this book. Some of the more advanced topics require some degree of familiarity with Perl..."
This assertion seems a bit over-optimistic on the part of the authors or the editor. Certainly the concept of templates is accessible to anyone who has used any form of macro substitution in the preparation of text documents, such as the mail merge feature of popular word processors. But Perldeep, profound Perlpermeates Perl Template Toolkit. Even the initial section on "Installing the Template Toolkit" goes on for pages, offers suggestions for the make, and proffers various URLs, interestingly omitting to mention the simplest and most reliable method of installing and configuring CPAN offerings for use:
cpan: install Template
Sometimes, experts find an aspect of their work so elementary they are convinced it will be simple to any reader, forgetting that merely the peculiar use of nonalphanumeric characters in the most basic Perl syntax can stun the nonexpert like a deer being caught in the headlights. You do want to know Perl to buy this book, but if you are on a team, you can certainly lend this book to a document preparer who is not a Perl programmer, while expecting to be called upon to mentor that individual. Setting up a development chain and production system leveraging the Template Toolkit is definitely not end-user work, though the authors are correct that end users with little or no programming experience can be expected to maintain many kinds of templates themselves, once the basic templates for the project have been written or at least exemplified.
Another grimly humorous aspect of the whole pursuit is that if you wish to run the examples that involve an Apache web server (really the meat of the book), you must take advantage of the extensive information contained in Perl Template Toolkit for configuring the Apache::Template module under mod_perl, which means that you may find you need to read another O'Reilly offering, Practical mod_perl, if you haven't already figured out how to adequately configure mod_perl. When I got right down to it, I discovered that being adequately configured on my home Solaris/Linux/BSD boxes in order to riffle through the code in this book was nontrivial, though quite enjoyable and [re]educational (web server configuration being one of those things you put out of mind when not dealing directly with it on a day-by-day basis). I found myself updating my Apache version and building or re-building bunches of Perl modules, including mod_perl as a minimum requirement to review this book.
Lastly, I find that the downloadable source code to accompany the book is indifferently presented, just sort of glommed onto HTML pages with none of the care or stylishness that distinguishes the rest of the literary effort. This can always be cleaned up over time, of course, on the source web site; one hopes the authors will make the post-production effort to generate a somewhat cleverer source presentation for their readers.
The book's web site (http://www.oreilly.com/catalog/perltt/ index.html) offers the usual summary, table of contents, sample chapter, example code, etc. The Template Toolkit also has its own website at http://template-toolkit.org/.
TPJ