Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Building a New Frontend The Template module is the default frontend to the Template Toolkit, but there are others. The Apache::Template module, available from CPAN, is one, as are the familiar tpage and ttree. Here is a description of these default frontends: Template The Template module is the frontend that most users are familiar with. Template provides the familiar process method: $tt->process($input, $vars, $output) || die $tt->error( ); Template uses the underlying Template::Service instance internally to process $input , and then redirect that output appropriately, based on the third argument to process( ) (see Chapter 7 for details). Apache::Template The Apache::Template module provides a simple interface to the Template Toolkit from Apache/mod_perl. Apache::Template allows configuration to be handled in an Apache-specific manner, using directives in Apache's httpd.conf configuration file. Apache::Template is covered in Chapter 12. The Appendix lists valid Apache::Tem plate -related httpd.conf configuration directives. tpage and ttree We've already met tpage and ttree in Chapter 1 and Chapter 2; these two scripts are also Template Toolkit frontends. A Template Toolkit frontend manages the Template::Service instance, and, generally, manages input and output. In this section, we look at these standard frontends and how to build a custom frontend for email. Mail::Template Because email is basically text, and generating text is so simple using the Template Toolkit, why isn't there a dedicated mail frontend? Well, there could be; let's develop one. Our Template Toolkit frontend module needs two user-facing methods, new and proc ess . The Template::Base module implements most of the common functionality of the modules that ship with the Template Toolkit, so we can start there: package Mail::Template; use strict; use vars qw($VERSION $MAILHOST $MAILPORT); use base qw(Template::Base); use Mail::Sendmail qw(sendmail); Building a New Frontend | 337