perl-modperl-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbek...@apache.org
Subject cvs commit: modperl-site/features tmpl-cmp.html
Date Wed, 01 Aug 2001 03:35:13 GMT
sbekman     01/07/31 20:35:13

  Modified:    .        index.html
  Added:       features tmpl-cmp.html
  Log:
  adding Perrin's templates comparison doc
  
  Revision  Changes    Path
  1.84      +102 -73   modperl-site/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/modperl-site/index.html,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- index.html	2001/07/17 15:29:00	1.83
  +++ index.html	2001/08/01 03:35:13	1.84
  @@ -78,6 +78,10 @@
   	      <a href="#docs">Documentation</a>
   	    </li>
   
  +            <li>
  +              <a href="#features">Features</a>        
  +            </li>
  + 
   	    <li>
   	      <a href="#modules">Perl Apache::* Modules</a>	      
   	    </li>
  @@ -99,11 +103,12 @@
   		
   	    </li>
   
  -	    <li>
  -	      <a href="#appservers">Application Servers/Toolkits/Embedding Perl into HTML/XML publishing running with mod_perl</a>	      
  -	    </li>
  -
   	    <li>
  +	      <a href="#appservers">Application Servers, Toolkits,
  +	      Embedding Perl into HTML, XML publishing running with mod_perl</a>	      
  +	    </li>
  +
  +	    <li>
                 <a href="help_with_modules_wanted.html">Help with
                 Perl Apache Modules Wanted</a>
   	    </li>
  @@ -213,6 +218,30 @@
   
   
         <tr>
  +        <td>
  +
  +          <h3><font color="#008B8B">
  +              <a name="features">
  +                Features
  +              </a>
  +            </font>
  +          </h3>
  +          
  +          <ul>
  +          <li><a href="features/tmpl-cmp.html">Templates comparison</a></li>
  +          <li><a href=""></a></li>
  +          </ul>
  +
  +          [ <a href="#toc">toc</a> ]
  +
  +          <br><br><br><br><br><br><br>
  +        
  +          <hr>
  +        </td>
  +      </tr>
  +
  +
  +      <tr>
   	<td>
   
   	  <h3><font color="#008B8B">
  @@ -690,9 +719,9 @@
   	  <hr width="40%" align="left">
   	  
   	  <p><a name="embperl-list"></a>
  -	    The <b>embperl mailing list</b> is available for
  -	    <a href="http://perl.apache.org/embperl/">Embperl</a> users and developers to 
  -		share ideas, ask question and solve problems.
  +	    The <b>embperl mailing list</b> is available for
  +	    <a href="http://perl.apache.org/embperl/">Embperl</a> users and developers to 
  +		share ideas, ask question and solve problems.
   	    <br>
   	  </p>
   
  @@ -721,11 +750,11 @@
   	  <p>
   	    List's searchable archives:
   	  <ul>   
  +
  +	    <li>
  +               <a href="http://www.ecos.de/~mailarc/embperl/">ecos.de</a>
  +	    </li>
   
  -	    <li>
  -               <a href="http://www.ecos.de/~mailarc/embperl/">ecos.de</a>
  -	    </li>
  -
   	    <li>
                  <a href="http://www.geocrawler.com/lists/3/Web/187/0/">geocrawel.com</a>
   	    </li>
  @@ -845,33 +874,33 @@
   
   	  <h3><font color="#008B8B">
   	      <a name="appservers">
  -                Application Servers/Toolkits/Embedding Perl into HTML/XML publishing running with mod_perl
  +                Application Servers/Toolkits/Embedding Perl into HTML/XML publishing running with mod_perl
   	      </a>
   	    </font>
   	  </h3>
  -		<font color="#008B8B" size="-1">(in alphabeticaly order)</font><br>
  +		<font color="#008B8B" size="-1">(in alphabeticaly order)</font><br>
   
   	  <ul>
  +
  +	    <li>
  +			<a href="http://www.apache-asp.org/">Apache::ASP</a> provides
  +			an Active Server Pages port to the Apache Web Server with Perl
  +			scripting only, and enables developing of dynamic web applications
  +			with session management and embedded perl code. There are also 
  +			many powerful extensions, including XML taglibs, XSLT rendering, 
  +			and new events not originally part of the ASP API
  +	    </li>
   
  -	    <li>
  -			<a href="http://www.apache-asp.org/">Apache::ASP</a> provides
  -			an Active Server Pages port to the Apache Web Server with Perl
  -			scripting only, and enables developing of dynamic web applications
  -			with session management and embedded perl code. There are also 
  -			many powerful extensions, including XML taglibs, XSLT rendering, 
  -			and new events not originally part of the ASP API
  -	    </li>
  -
  -	    <li> 
  -			<a href="http://pagekit.org/">Apache::PageKit</a> is a
  -			web application framework that uses HTML::Template and
  -			XML to separate the Model, View, Content and
  -			Controller. Provides elegant solutions to many difficult
  -			web programming problems, including session management,
  -			language localization, authentication, form validation,
  -			and co-branding.
  -        </li>
  -
  +	    <li> 
  +			<a href="http://pagekit.org/">Apache::PageKit</a> is a
  +			web application framework that uses HTML::Template and
  +			XML to separate the Model, View, Content and
  +			Controller. Provides elegant solutions to many difficult
  +			web programming problems, including session management,
  +			language localization, authentication, form validation,
  +			and co-branding.
  +        </li>
  +
   	    <li>
   			<a href="http://axkit.org/">AxKit</a> is an XML
   			Application Server for Apache. It provides on-the-fly
  @@ -881,48 +910,48 @@
   			to provide some amazingly powerful techniques for XML
   			transformation.
   	    </li>
  +
  +	    <li> 
  +
  +              <a href="http://www.masonhq.com/">Mason</a> is a
  +              powerful Perl-based web site development and delivery
  +              engine.  With Mason you can embed Perl code in your HTML
  +              and construct pages from shared, reusable components.
  +              Mason solves the common problems of site development:
  +              caching, debugging, templating, simulating browser
  +              conditions, maintaining development and production
  +              sites, and more
  +
  +            </li>
  +
  +	    <li> 
  +
  +			<a href="http://perl.apache.org/embperl/">Embperl</a>
  +			is a system for building dynamic websites with Perl.
  +			It gives you the power to embed Perl code in your HTML documents
  +			and the ability to build your Web site out of small reusable objects in
  +			an object-oriented style. You can also take advantage of all the
  +			usual Perl modules, (including DBI for database access) use their
  +			functionality and easily include their output in your web pages.
  +			Embperl has several features which are especially useful for creating
  +			HTML, including dynamic tables, form field processing, URL
  +			escaping/unescaping, session handling, and more.
  +            </li>
  +
  +
  +	    <li> 
  +
  +              <a href="http://www.openinteract.org/">OpenInteract</a>
  +              is a web application environment written in perl and
  +              geared to run on the Apache web server using the
  +              mod_perl plugin module. The environment is built to be
  +              not only friendly to people editing and changing a
  +              website's content, but also for the developers who can
  +              write code (or complex templates) and create entire
  +              applications.
  +
  +            </li>
   
  -	    <li> 
  -
  -              <a href="http://www.masonhq.com/">Mason</a> is a
  -              powerful Perl-based web site development and delivery
  -              engine.  With Mason you can embed Perl code in your HTML
  -              and construct pages from shared, reusable components.
  -              Mason solves the common problems of site development:
  -              caching, debugging, templating, simulating browser
  -              conditions, maintaining development and production
  -              sites, and more
  -
  -            </li>
  -
  -	    <li> 
  -
  -			<a href="http://perl.apache.org/embperl/">Embperl</a>
  -			is a system for building dynamic websites with Perl.
  -			It gives you the power to embed Perl code in your HTML documents
  -			and the ability to build your Web site out of small reusable objects in
  -			an object-oriented style. You can also take advantage of all the
  -			usual Perl modules, (including DBI for database access) use their
  -			functionality and easily include their output in your web pages.
  -			Embperl has several features which are especially useful for creating
  -			HTML, including dynamic tables, form field processing, URL
  -			escaping/unescaping, session handling, and more.
  -            </li>
  -
  -
  -	    <li> 
  -
  -              <a href="http://www.openinteract.org/">OpenInteract</a>
  -              is a web application environment written in perl and
  -              geared to run on the Apache web server using the
  -              mod_perl plugin module. The environment is built to be
  -              not only friendly to people editing and changing a
  -              website's content, but also for the developers who can
  -              write code (or complex templates) and create entire
  -              applications.
  -
  -            </li>
  -
   	    <li> 
   
                 <a href="http://template-toolkit.org/">The Template
  
  
  
  1.1                  modperl-site/features/tmpl-cmp.html
  
  Index: tmpl-cmp.html
  ===================================================================
  <HTML>
  <HEAD>
  <TITLE>Choosing a Templating System</TITLE>
  </HEAD>
  
  <BODY bgcolor="#ffffff">
  
  <A NAME="__index__"></A>
  <!-- INDEX BEGIN -->
  
  <UL>
  
  	<LI><A HREF="#choosing a templating system">Choosing a Templating System</A></LI>
  	<LI><A HREF="#introduction">Introduction</A></LI>
  	<UL>
  
  		<LI><A HREF="#on a personal note">On A Personal Note</A></LI>
  	</UL>
  
  	<LI><A HREF="#why use templates">Why Use Templates?</A></LI>
  	<UL>
  
  		<LI><A HREF="#consistency of appearance">Consistency of Appearance</A></LI>
  		<LI><A HREF="#reusability">Reusability</A></LI>
  		<LI><A HREF="#better isolation from changes">Better Isolation from Changes</A></LI>
  		<LI><A HREF="#division of labor">Division of Labor</A></LI>
  	</UL>
  
  	<LI><A HREF="#what are the differences">What Are the Differences?</A></LI>
  	<UL>
  
  		<LI><A HREF="#execution models">Execution Models</A></LI>
  		<LI><A HREF="#languages">Languages</A></LI>
  		<LI><A HREF="#parsers and caching">Parsers and Caching</A></LI>
  		<LI><A HREF="#application frameworks vs. just templates">Application Frameworks vs. Just Templates</A></LI>
  		<UL>
  
  			<LI><A HREF="#url mapping">URL Mapping</A></LI>
  			<LI><A HREF="#session tracking">Session Tracking</A></LI>
  			<LI><A HREF="#output caching">Output Caching</A></LI>
  			<LI><A HREF="#form handling">Form Handling</A></LI>
  			<LI><A HREF="#debugging">Debugging</A></LI>
  		</UL>
  
  	</UL>
  
  	<LI><A HREF="#the contenders">The Contenders</A></LI>
  	<UL>
  
  		<LI><A HREF="#ssi">SSI</A></LI>
  		<LI><A HREF="#html::mason">HTML::Mason</A></LI>
  		<LI><A HREF="#html::embperl">HTML::Embperl</A></LI>
  		<LI><A HREF="#apache::axkit">Apache::AxKit</A></LI>
  		<LI><A HREF="#apache::asp">Apache::ASP</A></LI>
  		<LI><A HREF="#text::template">Text::Template</A></LI>
  		<LI><A HREF="#template toolkit">Template Toolkit</A></LI>
  		<LI><A HREF="#html::template">HTML::Template</A></LI>
  		<LI><A HREF="#html_tree">HTML_Tree</A></LI>
  		<LI><A HREF="#apache::xpp">Apache::XPP</A></LI>
  		<LI><A HREF="#eperl">ePerl</A></LI>
  		<LI><A HREF="#cgi::fasttemplate">CGI::FastTemplate</A></LI>
  	</UL>
  
  	<LI><A HREF="#performance">Performance</A></LI>
  	<UL>
  
  		<LI><A HREF="#cgi performance concerns">CGI Performance Concerns</A></LI>
  	</UL>
  
  	<LI><A HREF="#matrix">Matrix</A></LI>
  	<LI><A HREF="#updates">Updates</A></LI>
  </UL>
  <!-- INDEX END -->
  
  <HR>
  <P>
  <H1><A NAME="choosing a templating system">Choosing a Templating System</A></H1>
  <P>by Perrin Harkins</P>
  <P>Version 0.9<P>
  <HR>
  <H1><A NAME="introduction">Introduction</A></H1>
  <P>Go on, admit it: you've written a templating system.  It's okay,
  nearly everyone has at some point.  You start out with something
  beautifully simple like <CODE>$HTML =~ s/\$(\w+)/${$1}/g</CODE> and end up
  adding conditionals and loops and includes until you've created your
  very own unmaintainable monster.</P>
  <P>Luckily for you, you are not the first to think it might be nice to get
  the HTML out of your code.  Many have come before, and more than a few
  have put their contributions up on CPAN.  At this time, there are so
  many templating modules on CPAN that it's almost certain you can find
  one that meets your needs.  This document aims to be your guide to
  those modules, leading you down the path to the templating system of
  your dreams.</P>
  <P>And, if you just went straight to CPAN in the first place and never
  bothered to write your own, congratulations: you're one step ahead of
  the rest of us.</P>
  <P>
  <H2><A NAME="on a personal note">On A Personal Note</A></H2>
  <P>Nothing can start an argument faster on the mod_perl mailing list than
  a claim that one approach to templating is better than another.
  People get very attached to the tools they've chosen.  Therefore, let
  me say up front that I am biased.  I've been at this for a while and I
  have opinions about what works best.  I've tried to present a balanced
  appraisal of the features of various systems in this document, but it
  probably won't take you long to figure out what I like.  Besides,
  attempts to be completely unbiased lead to useless documents that
  don't contain any real information.  So take it all with a pound of
  salt and if you think I've been unfair to a particular tool through a
  factual error or omission, let me know.</P>
  <P>
  <HR>
  <H1><A NAME="why use templates">Why Use Templates?</A></H1>
  <P>Why bother using templates at all?  Print statements and CGI.pm were
  good enough for Grandpa, so why should you bother learning a new way
  to do things?</P>
  <P>
  <H2><A NAME="consistency of appearance">Consistency of Appearance</A></H2>
  <P>It doesn't take a genius to see that making one navigation bar
  template and using it in all of your pages is easier to manage than
  hard-coding it every where.  If you build your whole site like this,
  it's much easier to make site-wide changes in the look and feel.</P>
  <P>
  <H2><A NAME="reusability">Reusability</A></H2>
  <P>Along the same lines, building a set of commonly used components makes
  it easier to create new pages.</P>
  <P>
  <H2><A NAME="better isolation from changes">Better Isolation from Changes</A></H2>
  <P>Which one changes more often, the logic of your application or the
  HTML used to display it?  It actually doesn't matter which you
  answered, as long as it's one of them.  Templates can be a great
  abstraction layer between the application logic and the display logic,
  allowing one to be updated without touching the other.</P>
  <P>
  <H2><A NAME="division of labor">Division of Labor</A></H2>
  <P>Separating your Perl code from your HTML means that when your
  marketing department decides everything should be green instead of
  blue, you don't have to lift a finger.  Just send them to the HTML
  coder down the hall.  It's a beautiful thing, getting out of the HTML
  business.</P>
  <P>Even if the same people in your organization write the Perl code and
  the HTML, you at last have the opportunity for more people to be
  working on the project in parallel.</P>
  <P>
  <HR>
  <H1><A NAME="what are the differences">What Are the Differences?</A></H1>
  <P>Before we look at the available options, let's go through an
  explanation of some of the things that make them different.</P>
  <P>
  <H2><A NAME="execution models">Execution Models</A></H2>
  <P>Although some try to be flexible about it, most templating systems
  expect you to use some variation of the two basic execution models,
  which I will refer to as ``pipeline'' and ``callback.''  In the callback
  style, you let the template take over and it has the application's
  control flow coded into it.  It uses callbacks to modules or snippets
  of in-line Perl code to retrieve data for display or perform actions
  like user authentication.  Some popular examples of systems using this
  model include Mason, Embperl, and Apache::ASP.</P>
  <P>The pipeline style does all the work up front in a standard CGI or
  mod_perl handler, then decides which template to run and passes some
  data to it.  The template has no control flow logic in it, just
  presentation logic, e.g. show this graphic if this item is on sale.
  Popular systems supporting this approach include HTML::Template and
  Template Toolkit.</P>
  <P>The callback model works very well for publishing-oriented sites where
  the pages are essentially mix and match sets of articles and lists.
  Ideally, a site can be broken down into visual ``components'' or pieces
  of pages which are general enough for an HTML coder to re-combine them
  into entirely new kinds of pages without any help from a programmer.</P>
  <P>The callback model can get a bit hairy when you have to code logic
  that can result in totally different content being returned.  For
  example, if you have a system that processes some form input and takes
  the user to different pages depending on the data submitted.  In these
  situations, it's easy to end up coding a spaghetti of includes and
  redirects, or putting what are really multiple pages in the same file.</P>
  <P>On the other hand, a callback approach can result in fewer files (if
  the Perl code is in the HTML file), and feels easier and more
  intuitive to many developers.  It's a simple step from static files to
  static files with a few in-line snippets of code in them.  This is part
  of why PHP is so popular with new developers.</P>
  <P>The pipeline model is more like a traditional model-view-controller
  design.  Working this way can provide additional performance tuning
  opportunities over an approach where you don't know what data will be
  needed at the beginning of the request.  You can aggregate database
  queries, make smarter choices about caching, etc.  It can also promote
  a cleaner separation of application logic and presentation.  However,
  this approach takes longer to get started with since it's a bigger
  conceptual hurdle and always involves at least two files: one for the
  Perl code and one for the template.</P>
  <P>Keep in mind, many systems offer significant flexibility for
  customizing their execution models.  For example, Mason users could
  write separate components for application logic and display, letting
  the logic components choose which display component to run after
  fetching their data.  This allows it to be used in a pipeline style.
  A Template Toolkit application could be written to use a simple
  generic handler (like the Apache::Template module included in the
  distribution) with all the application logic placed in the template
  using object calls or in-line Perl.  This would be using it in a
  callback style.</P>
  <P>HTML::Template and some of the AxKit XML processors are fairly rigid
  about insisting on a pipeline approach.  Neither provide methods for
  calling back into Perl code during the HTML formatting stage; you have
  to do the work before running the template.  The authors of these
  tools consider this a feature since it prevents developers from
  cheating on the separation of application code and presentation.</P>
  <P>
  <H2><A NAME="languages">Languages</A></H2>
  <P>Here's the big issue with templating systems.  This is the one that
  always cranks up the flame on web development mailing lists.</P>
  <P>Some systems use in-line Perl statements.  They may provide some extra
  semantics, like Embperl's operators for specifying whether the code's
  output should be displayed or Mason's &lt;%init&gt; sections for specifying
  when the code gets run, but at the end of the day your templates are
  written in Perl.</P>
  <P>Other systems provide a specialized mini-language instead of (or in
  addition to) in-line Perl.  These will typically have just enough
  syntax to handle variable substitution, conditionals, and looping.
  HTML::Template and Template Toolkit are popular systems using this
  approach.  AxKit straddles the fence, providing both a (not-so-)
  mini-language - XSLT - and an in-line Perl approach - XPathScript.</P>
  <P>Here's how a typical discussion of the merits of these approaches might go:</P>
  <P><STRONG>IN-LINE:</STRONG> Mini-languages are stupid.  I already know Perl and it's easy
  enough.  Why would you want to use something different?</P>
  <P><STRONG>MINI-LANG:</STRONG> Because my HTML coder doesn't know Perl, and this is easier
  for him.</P>
  <P><STRONG>IN-LINE:</STRONG> Maybe he should learn some Perl.  He'd get paid more.</P>
  <P><STRONG>MINI-LANG:</STRONG> Whatever.  You just want to use in-line Perl so you can
  handle change requests by putting little hacks in the template instead
  of changing your modules.  That's sloppy coding.</P>
  <P><STRONG>IN-LINE:</STRONG> That's efficient coding.  I can knock out data editing
  screens in half the time it takes you, and then I can go back through,
  putting all the in-line code into modules and just have the templates
  call them.</P>
  <P><STRONG>MINI-LANG:</STRONG> You could, but you won't.</P>
  <P><STRONG>IN-LINE:</STRONG> Is it chilly up there in that ivory tower?</P>
  <P><STRONG>MINI-LANG:</STRONG> Go write some VBScript, weenie.</P>
  <P>etc.</P>
  <P>Most people pick a side in this war and stay there.  If you are one of
  the few who hasn't fully decided yet, you should take a moment to
  think about who will be building and maintaining your templates, what
  skills those people have, and what will allow them to work most
  efficiently.</P>
  <P>Here's an example of a simple chunk of template using first an in-line
  style (Apache::ASP in this case) and then a mini-language style
  (Template Toolkit).  This code fetches an object and displays some
  properties of it.  The data structures used are identical in both
  examples.  First Apache::ASP:</P>
  <PRE>
    &lt;% my $product = Product-&gt;load('sku' =&gt; 'bar1234'); %&gt;</PRE>
  <PRE>
    &lt;% if ($product-&gt;isbn) { %&gt;
      It's a book!
    &lt;% } else { %&gt;
      It's NOT a book!
    &lt;% } %&gt;</PRE>
  <PRE>
    &lt;% foreach my $item (@{$product-&gt;related}) { %&gt;
      You might also enjoy &lt;% $item-&gt;name %&gt;.
    &lt;% } %&gt;</PRE>
  <P>And now Template Toolkit:</P>
  <PRE>
    [% USE product(sku=bar1234) %]</PRE>
  <PRE>
    [% IF product.isbn %]
      It's a book!
    [% ELSE %]
      It's NOT a book!
    [% END %]
  </PRE>
  <PRE>
  
    [% FOREACH item = product.related %]
      You might also enjoy [% item.name %].
    [% END %]</PRE>
  <P>There is a third approach, based on parsing an HTML document into a
  DOM tree and then manipulating the contents of the nodes.  The only
  module using this approach is HTML_Tree.  The idea is similar to using
  a mini-language, but it doesn't require any non-standard HTML tags and
  it doesn't embed any logic about loops or conditionals in the template
  itself.  This is nice because it means your templates are valid HTML
  documents that can be viewed in a browser and worked with in most
  standard HTML tools.  It also means people working with the templates
  can put placeholder data in them for testing and it will simply be
  replaced when the template is used.  This preview ability only breaks
  down when you need an if/else type construct in the template.  In that
  situation, both the ``if'' and ``else'' chunks of HTML would show up when
  previewing.</P>
  <P>
  <H2><A NAME="parsers and caching">Parsers and Caching</A></H2>
  <P>The parsers for these templating systems are implemented in one of
  three ways: they parse the template every time (``repeated parse''),
  they parse it and cache the resulting parse tree (``cached parse
  tree''), or they parse it, convert it to Perl code, and compile it
  (``compiled'').</P>
  <P>Systems that compile templates to Perl take advantage of Perl's
  powerful runtime code evaluation capabilities.  They examine the
  template, generate a chunk of Perl code from it, and <CODE>eval</CODE> the
  generated code.  After that, subsequent requests for the template can
  be handled by running the compiled bytecode in memory.  The complexity
  of the parsing and code generation steps varies based on the number of
  bells and whistles the system provides beyond straight in-line Perl
  statements.</P>
  <P>Compiling to Perl and then to Perl bytecode is slow on the first hit
  but provides excellent performance once the template has been
  compiled, since the template becomes a Perl subroutine call.  This is
  the same approach used by systems like JSP (Java ServerPages).  It is
  most effective in environments with a long-running Perl interpreter,
  like mod_perl.</P>
  <P>HTML::Template, HTML_Tree, and the 2.0 beta release of Embperl all use
  a cached parse tree approach.  They parse templates into their
  respective internal data structures and then keep the parsed structure
  for each processed template in memory.  This is similar to the
  compiled Perl approach in terms of performance and memory
  requirements, but does not actually involve Perl code generation and
  thus doesn't require an <CODE>eval</CODE> step.  Which way is faster, caching
  the parse tree or compiling?  It's hard to objectively measure, but
  anecdotal evidence seems to support compilation.  Template Toolkit
  used a cached parse tree approach for version 1, but switched to a
  compilation approach for version 2 after tests showed it to offer a
  significant speed increase.  However, as will be discussed later,
  either approach is more than fast enough.</P>
  <P>In contrast to this, a repeated parse approach may sound very slow.
  However, it can be pretty fast if the tokens being parsed for are
  simple enough.  Systems using this approach generally use very simple
  tokens, which allows them to use fast and simple parsers.</P>
  <P>Why would you ever use a system with this approach if compilation has
  better performance?  Well, in an environment without a persistent Perl
  interpreter like vanilla CGI this can actually be faster than a
  compiled approach since the startup cost is lower.  The caching of
  Perl bytecode done by compilation systems is useless when the Perl
  interpreter doesn't stick around for more than one request.</P>
  <P>There are other reasons too.  Compiled Perl code takes up a lot of
  memory.  If you have many unique templates, they can add up fast.
  Imagine how much RAM it would take up if every page that used
  server-side includes (SSI) had to stay in memory after it had been
  accessed.  (Don't worry, the <CODE>Apache::SSI</CODE> module doesn't use
  compilation so it doesn't have this problem.)</P>
  <P>
  <H2><A NAME="application frameworks vs. just templates">Application Frameworks vs. Just Templates</A></H2>
  <P>Some of the templating tools try to offer a comprehensive solution to
  the problems of web development.  Others offer just a templating
  solution and assume you will fit this together with other modules to
  build a complete system.</P>
  <P>Some common features offered in the frameworks include:</P>
  <P>
  <H3><A NAME="url mapping">URL Mapping</A></H3>
  <P>All of the frameworks offer a way to map a URL to a template file.  In
  addition to simple mappings similar to the handling of static
  documents, some offer ways to intercept all requests within a certain
  directory for pre-processing, or create an object inheritance scheme
  out of the directory structure of a site.</P>
  <P>
  <H3><A NAME="session tracking">Session Tracking</A></H3>
  <P>Most interactive sites need to use some kind of session tracking to
  associate application state data with a user.  Some tools make this
  very easy by handling all the cookies or URL-munging for you and
  letting you simply read and write from an object or hash that contains
  the current user's session data.  A common approach is to use the
  Apache::Session module for storage.</P>
  <P>
  <H3><A NAME="output caching">Output Caching</A></H3>
  <P>Caching is the key to good performance in many web systems, and some
  of these tools provide user-controlled caching of output.  This is one
  of the major features of both Mason and AxKit.  AxKit can cache at the
  page level, while Mason also offers fine-grained caching of components
  within the page.</P>
  <P>
  <H3><A NAME="form handling">Form Handling</A></H3>
  <P>How will you live without CGI.pm to parse incoming form data?  Many of
  these tools will do it for you, making it available in a convenient
  data structure.  Some also validate form input, and even provide
  ``sticky'' form widgets that keep their selected values when
  re-displayed or set up default values based on data you provide.</P>
  <P>
  <H3><A NAME="debugging">Debugging</A></H3>
  <P>Everyone knows how painful it can be to debug a CGI script.
  Templating systems can make it worse, by screwing up Perl's line
  numbers with generated code.  To help fix the problem they've created,
  some offer built-in debugging support, including extra logging, or
  integration with the Perl debugger.</P>
  <P>If you want to use a system that just does templates but you need some
  of these other features and don't feel like implementing them
  yourself, there are some tools on CPAN which provide a framework you
  can build on.  The libservlet distribution, which provides an
  interface similar to the Java servlet API, is independent of any
  particular templating system.  Apache::PageKit and CGI::Application
  are other options in this vein, but both of these are currently tied
  to HTML::Template.  OpenInteract is another framework, this time tied
  to Template Toolkit.  All of these could be adapted for the ``just
  templates'' module of your choice with fairly minimal effort.</P>
  <P>
  <HR>
  <H1><A NAME="the contenders">The Contenders</A></H1>
  <P>Okay, now that you know something about what separates these tools
  from each other, let's take a look at the top choices for Perl
  templating systems.  This is not an exhaustive list: I've only
  included systems that are currently maintained, well-documented, and
  have managed to build up a significant user community.  In short, I've
  left out a dozen or so less popular systems.  At the end of this
  section, I'll mention a few systems that aren't as commonly used but
  may be worth a look.</P>
  <P>
  <H2><A NAME="ssi">SSI</A></H2>
  <P>SSI is the granddaddy of templating systems, and the first one that
  many people used since it comes as a standard part of most web
  servers.  With mod_perl installed, mod_include gains some additional
  power.  Specifically, it is able to take a new #perl directive which
  allows for in-line subroutine calls.  It can also efficiently include
  the output of Apache::Registry scripts by using the Apache::Include
  module.</P>
  <P>The Apache::SSI module implements the functionality of mod_include
  entirely in Perl, including the additional #perl directive.  The main
  reasons to use it are to post-process the output of another handler
  (with Apache::Filter) or to add your own directives.  Adding
  directives is easy through subclassing.  You might be tempted to
  implement a complete template processor in this way, by adding loops
  and other constructs, but it's probably not worth the trouble with so
  many other tools out there.</P>
  <P>SSI follows the callback model and is mostly a mini-language, although
  you can sneak in bits of Perl code as anonymous subs in #perl
  directives.  Because SSI uses a repeated parse implementation, it is
  safe to use it on large numbers of files without worrying about memory
  bloat.</P>
  <P>SSI is a great choice for sites with fairly simple templating needs,
  especially ones that just want to share some standard headers and
  footers between pages.  However, you should consider whether or not
  your site will eventually need to grow into something with more
  flexibility and power before settling on this simple approach.</P>
  <P>
  <H2><A NAME="html::mason">HTML::Mason</A></H2>
  <P>Mason has been around for a few years now, and has built up a loyal
  following.  It was originally created as a Perl clone of some of the
  most interesting features from Vignette StoryServer, but has since
  become it's own unique animal.  It comes from a publishing background,
  and includes features oriented towards splitting up pages into
  re-useable chunks, or ``components.''</P>
  <P>Mason uses in-line Perl with a compilation approach, but has a feature
  to help keep the perl code out of the HTML coder's way.  Components
  (templates) can include a section of Perl at the end of the file which
  is wrapped inside a special tag indicating that it should be run
  first, before the rest of the template.  This allows programmers to
  put all the logic for a component down at the bottom away from the
  HTML, and then use short in-line Perl snippets in the HTML to insert
  values, loop through lists, etc.</P>
  <P>Mason is a site development framework, not just a templating tool.  It
  includes a very handy caching feature that can be used for capturing
  the output of components or simply storing data that is expensive to
  compute.  It is currently the only tool that offers this sort of
  caching as a built-in.  It also implements an argument parsing scheme
  which allows a component to specify the names, types, and default
  values that it expects to be passed, either from another component or
  from the values passed in the URI query string.</P>
  <P>While the documentation mostly demonstrates a callback execution
  model, it is possible to use Mason in a pipeline style.  This can be
  accomplished in various ways, including designating components as
  ``autohandlers'' which run before anything else for requests within a
  certain directory structure.  An autohandler could do some processing
  and set up data for a display template which only includes minimal
  in-line Perl.  There is also support for an object-oriented site
  approach, applying concepts like inheritance to the site directory
  structure.  For example, the component at /store/book/ might inherit a
  standard layout from the component at /store/, but override the
  background color and navigation bar.  Then /store/music/ can do the
  same, with a different color.  This can be a very powerful paradigm
  for developing large sites.</P>
  <P>Mason's approach to debugging is to create ``debug files'' which run
  Mason outside of a web server environment, providing a fake web
  request and activating the debugger.  This can be helpful if you're
  having trouble getting Apache::DB to behave under mod_perl, or using
  an execution environment that doesn't provide built-in debugger
  support.</P>
  <P>Another unique feature is the ability to leave the static text parts
  of a large template on disk, and pull them in with a file seek when
  needed rather than keeping them in RAM.  This exchanges some speed for
  a significant savings in memory when dealing with templates that are
  mostly static text.</P>
  <P>There are many other features in this package, including filtering of
  HTML output and a page previewing utility.  Session support is not
  built-in, but a simple example showing how to integrate with
  Apache::Session is included.  Mason's feature set can be a bit
  overwhelming for newbies, but the high-quality documentation and
  helpful user community go a long way.</P>
  <P>
  <H2><A NAME="html::embperl">HTML::Embperl</A></H2>
  <P>Embperl makes its language choice known up front: embedded perl.  It
  is one of the most popular in-line Perl templating tools and has been
  around longer than most of the others.  It has a solid reputation for
  speed and ease of use.</P>
  <P>It is commonly used in a callback style, with Embperl intercepting
  URIs and processing the requested file.  However, it can optionally be
  invoked through a subroutine call from another program, allowing it to
  be used in a pipeline style.  Templates are compiled to Perl bytecode
  and cached.</P>
  <P>Embperl has been around long enough to build up an impressive list of
  features.  It has the ability to run code inside a Safe compartment,
  support for automatically cleaning up globals to make mod_perl coding
  easier, and extensive debugging tools including the ability to e-mail
  errors to an administrator.</P>
  <P>The main thing that sets Embperl apart from other in-line Perl systems
  is its tight HTML integration.  It can recognize <CODE>TABLE</CODE> tags and
  automatically iterate over them for the length of an array.  It
  automatically provides sticky form widgets.  An array or hash
  reference placed at the end of a query string in an <CODE>HREF</CODE> or <CODE>SRC</CODE>
  attribute will be automatically expanded into query string
  ``name=value'' format.  <CODE>META HTTP-EQUIV</CODE> tags are turned into true HTTP
  headers.</P>
  <P>Another reason people like Embperl is that it makes some of the common
  tasks of web application coding so simple.  For example, all form data
  is always available just by reading the magic variable %fdat.
  Sessions are supported just as easily, by reading and writing to the
  magic %udat hash.  There is also a hash for storing persistent
  application state.  HTML-escaping is automatic (though it can be
  toggled on and off).</P>
  <P>Embperl includes something called EmbperlObject, which allows you to
  apply OO concepts to your site hierarchy in a similar way to the
  inheritance features mentioned for Mason, above.  This is a very
  convenient way to code sites with styles that vary by area, and is
  worth checking out.</P>
  <P>One drawback of older versions of Embperl was the necessity to use
  built-in replacements for most of Perl's control structures like ``if''
  and ``foreach'' when they are being wrapped around non-Perl sections.
  For example:</P>
  <PRE>
    [$ if ($foo) $]
      Looks like a foo!
    [$ else $]
      Nope, it's a bar.
    [$ endif $]</PRE>
  <P>These may seem out of place in a system based around in-line Perl.  As
  of version 1.2b2, it is possible to use Perl's standard syntax instead:</P>
  <PRE>
    [$ if ($foo) { $]
      Looks like a foo!
    [$ } else { $]
      Nope, it's a bar.
    [$ } $]</PRE>
  <P>At the time of this writing, a new 2.x branch of Embperl is in beta
  testing.  This includes some interesting features like a more flexible
  parsing scheme which can be modified to users' tastes.  it also
  supports direct use of the Perl debugger on Embperl templates, and
  provides performance improvements.</P>
  <P>
  <H2><A NAME="apache::axkit">Apache::AxKit</A></H2>
  <P>AxKit is the first mod_perl page generation system to be built from the
  ground up around XML.  Technically, AxKit itself is not a templating
  tool but rather a framework for stringing together different modules
  that generate and transform XML data.  In fact, it can optionally use
  Template Toolkit as an XML transformation language.  However, it
  deserves coverage here since it is also the home of some templating
  tools that are not represented elsewhere.</P>
  <P>In its simplest form, AxKit maps XML files to XSL stylesheets which it
  can process using commonly available XSLT modules like XML::XSLT or
  XML::Sablotron.  The rules for mapping a stylesheet to a request are
  very flexible, and they can incorporate query strings, cookies, and
  other attributes of the request.  The idea is that you can use this
  feature to handle a wide variety of clients with differing display
  capabilities by choosing the right stylesheet.</P>
  <P>Recognizing that not everyone is a fan of XSL's somewhat obtuse
  syntax, Matt Sergeant has provided an alternate stylesheet language
  called XPathScript.  XPathScript allows you to write a stylesheet
  using text with embedded Perl code.  This is similar to the other
  embedded Perl templating tools, but the focus is on using the built in
  XPath functions for querying an XML document and manipulating the
  retrieved data.  XPathScript can also be used in a declarative
  fashion, specifying the formatting of particular elements in the XML
  input.  For example this snippet will change all &lt;foo&gt; tags in an XML
  document to BAR in the output::</P>
  <PRE>
    &lt;%
      $t-&gt;{'foo'}{pre}   = 'BAR';
      $t-&gt;{'foo'}{post}    = '';
      $t-&gt;{'foo'}{showtag} = 0;
    %&gt;
    &lt;%= apply_templates() %&gt;</PRE>
  <P>By using XPathScript's include function (which looks just like SSI),
  you can build up libraries of useful transformations that use this
  technique.</P>
  <P>This is all well and good if you have a bunch of XML files sitting on
  a disk somewhere, but what about dynamic content?  AxKit handles this
  by allowing you to substitute a different data source for the default
  file-based one.  This can include running some dynamic code on each
  request to generate the XML data that will be transformed.  The
  distribution includes a module for doing this called XSP.  XSP is a
  language for building an XML DOM using in-line Perl and tag libraries.
  The tag libraries are specified as stylesheets which can turn XML tags
  into Perl code.  This is demonstrated through the included SQL tag
  library, which allows you to write an XSP page using XML tags which
  will connect to a database, execute queries, and generate an XML
  document with the results.</P>
  <P>AxKit has some nice performance boosts built into it.  It can cache
  the full output of a page and serve it as a static file on future
  requests.  It can also compress output to speed up downloads for
  browsers that understand gzip encoding.  These can be done with other
  systems, but they require you to setup additional software .  With
  AxKit, you just enable them in the configuration file.</P>
  <P>If all of these languages, tag libraries, and stylesheets sound
  intimidating to you, AxKit may be overkill for your project.  However,
  AxKit has the advantage of being built on approved W3C standards, and
  many of the skills used in developing for it carry over to other
  languages and tools.</P>
  <P>
  <H2><A NAME="apache::asp">Apache::ASP</A></H2>
  <P>Apache::ASP started out as a port of Microsoft's Active Server Pages
  technology, and its basic design still follows that model.  It uses
  in-line Perl with a compilation approach, and provides a set of simple
  objects for accessing the request information and formulating a
  response.  Scripts written for Microsoft's ASP using Perl (via
  ActiveState's PerlScript) can usually be run on this system without
  changes.  (Pages written in VBScript are not supported.)</P>
  <P>Like the original ASP, it has hooks for calling specified code when
  certain events are triggered, such as the start of a new user session.
  It also provides the same easy-to-use state and session management.
  Storing and retrieving state data for a whole application or a
  specific user is as simple as a single method call.  It can even
  support user sessions without cookies by munging URLs -- a unique
  feature among these systems.</P>
  <P>A significant addition that did not come from Microsoft ASP is the XML
  and XSLT support.  There are two options provided: XMLSubs and XSLT
  transforms.  XMLSubs is a way of adding custom tags to your pages.  It
  maps XML tags to your subroutines, so that you can add something like
  <CODE>&lt;site:header page=&quot;Page Title&quot; /&gt;</CODE> to your pages and have it
  translate into a subroutine call like <CODE>&amp;site::header({title =&gt;
  &quot;Page Title&quot;})</CODE>.  It can handle processing XML tags with body text as
  well.</P>
  <P>The XSLT support allows the output of ASP scripts to be filtered
  through XSLT for presentation.  This allows your ASP scripts to
  generate XML data and then format that data with a separate XSL
  stylesheet.  This support is provided through integration with the
  XML::XSLT module.</P>
  <P>Apache::ASP provides sticky widgets for forms through the use of the
  HTML::FillInForm module.  It also has built-in support for removing
  extra whitespace from generated output, gzip compressing output (for
  browsers that support it), tracking performance using Time::HiRes,
  automatically mailing error messages to an administrator, and many
  other conveniences and tuning options.  This is a mature package which
  has evolved to handle real-world problems.</P>
  <P>One thing to note about the session and state management in this
  system is that it currently only supports clusters through the use of
  network filesystems like NFS or SMB.  (Joshua Chamas, the module's
  author, has reported much better results from Samba file-sharing than
  from NFS.)  This may be an issue for large-scale server clusters,
  which usually rely on a relational database for network storage of
  sessions.  Support database storage of sessions is planned for a
  future release.</P>
  <P>
  <H2><A NAME="text::template">Text::Template</A></H2>
  <P>This module has become the de facto standard general purpose
  templating module on CPAN.  It has an easy interface and thorough
  documentation.  The examples in the docs show a pipeline execution
  style, but it's easy to write a mod_perl handler that directly invokes
  templates, allowing a callback style.  The module uses in-line Perl.
  It has the ability to run the in-line code in a Safe compartment, in
  case you are concerned about mistakes in the code crashing your
  server.</P>
  <P>The module relies on creative uses of in-line code to provide things
  that people usually expect from templating tools, like includes.  This
  can be good or bad.  For example, to include a file you could just
  call Text::Template::fill_in_file(filename).  However, you'll have to
  specify the complete file path and nothing will stop you from using
  /etc/passwd as the file to be included.  Most of the fancier
  templating tools have concepts like include paths, which allow you to
  specify a list of directories to search for included files.  You could
  write a subroutine that works this way, and make it available in your
  template's namespace, but it's not built in.</P>
  <P>Each template is loaded as a separate object.  Templates are compiled
  to Perl and only parsed the first time they are used.  However, to
  take full advantage of this caching in a persistent environment like
  mod_perl, your program will have to keep track of which templates have
  been used, since Text::Template does not have a way of globally
  tracking this and returning cached templates when possible.</P>
  <P>Text::Template is not tied to HTML, and is just a templating module,
  not a web application framework.  It is perfectly at home generating
  e-mails, PDFs, etc.</P>
  <P>
  <H2><A NAME="template toolkit">Template Toolkit</A></H2>
  <P>One of the more recent additions to the templating scene, Template
  Toolkit is a very flexible mini-language system.  It has a complete
  set of directives for working with data, including loops and
  conditionals, and it can be extended in a number of ways.  In-line
  Perl code can be enabled with a configuration option, but is generally
  discouraged.  It uses compilation, caching the compiled bytecode in
  memory and optionally caching the generated Perl code for templates on
  disk.  Although it is commonly used in a pipeline style, the included
  Apache::Template module allows templates to be invoked directly from
  URLs.</P>
  <P>Template Toolkit has a large feature set, so we'll only be able cover
  some of the highlights here.  The TT distribution sets a gold standard
  for documentation thoroughness and quality, so it's easy to learn more
  if you choose to.</P>
  <P>One major difference between TT and other systems is that it provides
  simple access to complex data structures through the concept of a dot
  operator.  This allows people who don't know Perl to access nested
  lists and hashes or call object methods.  For example, we could pass
  in this Perl data structure:</P>
  <PRE>
    $vars = {
             customer =&gt; {
                          name    =&gt; 'Bubbles',
                          address =&gt; {
                                      city =&gt; 'Townsville',
                                     }
                         }
            };</PRE>
  <P>Then we can refer to the nested data in the template:</P>
  <PRE>
    Hi there, [% customer.name %]!
    How are things in [% customer.address.city %]?</PRE>
  <P>This is simpler and more uniform than the equivalent syntax in Perl.
  If we pass in an object as part of the data structure, we can use the
  same notation to call methods within that object.  If you've modeled
  your system's data as a set of objects, this can be very convenient.</P>
  <P>Templates can define macros and include other templates, and
  parameters can be passed to either.  Included templates can optionally
  localize their variables so that changes made while the included
  template is executing do not affect the values of variables in the
  larger scope.</P>
  <P>There is a filter directive, which can be used for post-processing
  output.  Uses for this range from simple HTML entity conversion to
  automatic truncation (useful for pulldown menus when you want to limit
  the size of entries) and printing to STDERR.</P>
  <P>TT supports a plugin API, which can be used to add extra capabilities
  to your templates.  The provided plugins can be broadly organized into
  data access and formatting.  Standard data access plugins include
  modules for accessing XML data or a DBI data source and using that
  data within your template.  There's a plugin for access to CGI.pm as
  well.</P>
  <P>Formatting plugins allow you to display things like dates and prices
  in a localized style.  There's also a table plugin for use in
  displaying lists in a multi-column format.  These formatting plugins
  do a good job of covering the final 5% of data display problems that
  often cause people who are using an in-house system to embed a little
  bit of HTML in their Perl modules.</P>
  <P>In a similar vein, TT includes some nice convenience features for
  template writers like eliminating white space around tags and the
  ability to change the tag delimiters -- things that may sound a little
  esoteric, but can sometimes make templates significantly easier to
  work with.</P>
  <P>The TT distribution also includes a script called ttree which allows
  for processing an entire directory tree of templates.  This is useful
  for sites that pre-publish their templated pages and serve them
  statically.  The script checks modification times and only updates
  pages that require it, providing a make-like functionality.  The
  distribution also includes a sample set of template-driven HTML
  widgets which can be used to give a consistent look and feel to a
  collection of documents.</P>
  <P>
  <H2><A NAME="html::template">HTML::Template</A></H2>
  <P>HTML::Template is a popular module among those looking to use a
  mini-language rather than in-line Perl.  It uses a simple set of tags
  which allow looping (even on nested data structures) and conditionals
  in addition to basic value insertion.  The tags are intentionally
  styled to look like HTML tags, which may be useful for some
  situations.</P>
  <P>As the documentation says, it ``does just one thing and it does quickly
  and carefully'' -- there is no attempt to add application features like
  form-handling or session tracking.  The module follows a pipeline
  execution style.  Parsed templates are stored in a Perl data structure
  which can be cached in any combination of memory, shared memory (using
  IPC::SharedCache), and disk.  The documentation is complete and
  well-written, with plenty of examples.</P>
  <P>You may be wondering how this module is different from Template
  Toolkit, the other popular mini-language system.  Beyond the obvious
  differences in syntax, HTML::Template is faster and simpler, while
  Template Toolkit has more advanced features, like plugins and dot
  notation.  Here's a simple example comparing the syntax:</P>
  <P>HTML::Template:</P>
  <PRE>
    &lt;TMPL_LOOP list&gt;
        &lt;a href=&quot;&lt;TMPL_VAR url&gt;&quot;&gt;&lt;b&gt;&lt;TMPL_VAR name&gt;&lt;/b&gt;&lt;/A&gt;
    &lt;/TMPL_LOOP&gt;</PRE>
  <P>Template Toolkit:</P>
  <PRE>
    [% FOREACH list %]
        &lt;a href=&quot;[% url %]&quot;&gt;&lt;b&gt;[% name %]&lt;/a&gt;&lt;/a&gt;
    [% END %]</PRE>
  <P>And now, a few honorable mentions:</P>
  <P>
  <H2><A NAME="html_tree">HTML_Tree</A></H2>
  <P>As mentioned earlier, HTML Tree uses a fairly unique method of
  templating: it loads in an HTML page, parses it to a DOM, and then
  programmatically modifies the contents of nodes.  This allows it to
  use genuine valid HTML documents as templates, something which none of
  these other modules can do.  The learning curve is a little steeper
  than average, but this may be just the thing if you are concerned
  about keeping things simple for your HTML coders.  Note that the name
  is ``HTML_Tree'', not ``HTML::Tree''.</P>
  <P>
  <H2><A NAME="apache::xpp">Apache::XPP</A></H2>
  <P>XPP is an in-line Perl system that compiles to bytecode.  Although it
  is a perfectly good implementation, it has little to differentiate it
  except for an easy mechanism to define new HTML-like tags which can be
  used to replace in-line code in templates.</P>
  <P>
  <H2><A NAME="eperl">ePerl</A></H2>
  <P>Possibly the first module to embed Perl code in a text or HTML file,
  ePerl is still a viable option in the form of Apache::ePerl.  It
  caches compiled bytecode in memory to achieve solid performance, and
  some people find it refreshingly simple to use.</P>
  <P>
  <H2><A NAME="cgi::fasttemplate">CGI::FastTemplate</A></H2>
  <P>This module takes a minimalistic approach to templating, which makes
  it unusually well suited to use in CGI programs.  It parses templates
  with a single regular expression and does not support anything in
  templates beyond simple variable interpolation.  Loops are handled by
  including the output of other templates.  Unfortunately, this leads to
  a Perl coding style that is more confusing than most, and a
  proliferation of template files.  However, some people swear by this
  dirt-simple approach.</P>
  <P>
  <HR>
  <H1><A NAME="performance">Performance</A></H1>
  <P>People always seem to worry about the performance of templating
  systems.  If you've ever built a large-scale application, you should
  have enough perspective on the relative costs of different actions to
  know that your templating system is not the first place to look for
  performance gains.  All of the systems mentioned here have excellent
  performance characteristics in persistent execution environments like
  mod_perl.  Compared to such glacially slow operations as fetching data
  from a database or file, the time added by the templating system is
  almost negligible.</P>
  <P>If you think your templating system is slowing you down, get the
  facts: pull out Devel::DProf and see.  If one of the tools mentioned
  here is at the top of the list for wall clock time used, you should
  pat yourself on the back -- you've done a great job tuning your system
  and removing bottlenecks!  Personally, I have only seen this happen
  when I had managed to successfully cache nearly every part of the work
  to handle a request except running a template.</P>
  <P>However, if you really are in a situation where you need to squeeze a
  few extra microseconds out of your page generation time, there are
  performance differences between systems.  They're pretty much what you
  would expect: systems that do the least run the fastest.  Using
  in-line <CODE>print()</CODE> statements is faster than using templates.  Using
  simple substitution is faster than using in-line Perl code.  Using
  in-line Perl code is faster than using a mini-language.</P>
  <P>The only templating benchmark available at this time is one developed
  by Joshua Chamas, author of Apache::ASP.  It includes a ``hello world''
  test, which simply checks how fast each system can spit back those
  famous words, and a ``hello 2000'' test, which exercises the basic
  functions used in most dynamic pages.  It is available from the
  following URL:</P>
  <P><A HREF="http://www.chamas.com/bench/hello.tar.gz">http://www.chamas.com/bench/hello.tar.gz</A></P>
  <P>Results from this benchmark currently show SSI, Apache::ASP, and
  HTML::Embperl having the best performance of the lot.  Not all of the
  systems mentioned here are currently included in the test.  If your
  favorite was missed, you might want to download the benchmark code and
  add it.  As you can well imagine, benchmarking people's pet projects
  is largely a thankless task and Joshua deserves some recognition and
  support for this contribution to the community.</P>
  <P>
  <H2><A NAME="cgi performance concerns">CGI Performance Concerns</A></H2>
  <P>If you're running under CGI, you have bigger fish to fry than worrying
  about the performance of your templating system.  Nevertheless, some
  people are stuck with CGI but still want to use a templating system
  with reasonable performance.  CGI is a tricky situation, since you
  have to worry about how much time it will take for Perl to compile the
  code for a large templating system on each request.  CGI also breaks
  the in-memory caching of templates used by most of these systems,
  although the slower disk-based caching provided by Mason,
  HTML::Template, and Template Toolkit will still work.  (HTML::Template
  does provide a shared memory cache for templates, which may improve
  performance, although shared memory on my Linux system is usually
  slower than using the filesystem.  Benchmarks and additional
  information are welcome.)</P>
  <P>Your best performance bet with CGI is to use one of the simpler tools,
  like CGI::FastTemplate or Text::Template.  They are small and compile
  quickly, and CGI::FastTemplate gets an extra boost since it relies on
  simple regex parsing and doesn't need to eval any in-line Perl code.
  Almost everything else mentioned here will add tenths of seconds to
  each page in compilation time alone.</P>
  <P>
  <HR>
  <H1><A NAME="matrix">Matrix</A></H1>
  <P>To help you choose a system, I'll summarize the basic characteristics
  of the major systems along the decision points I've explained in the
  beginning of the article.  Keep in mind that in many cases a system
  can be used in more than one way, and I've simply shown the dominant
  method as seen in the documentation and real world use.  You should
  not eliminate options based on this chart without reading the more
  detailed explanations above.</P>
  <TABLE BORDER=1>
    <TR>
      <TH>
      </TD>
      <TH>
        Application Framework
      </TD>
      <TH>
        Pipeline or Callback
      </TD>
      <TH>
        Parsing Method
      </TD>
      <TH>
        Language
      </TD>
    </TR>
    <TR>
      <TD>
        HTML::Mason
      </TD>
      <TD>
        Framework
      </TD>
      <TD>
        Callback
      </TD>
      <TD>
        Compiled
      </TD>
      <TD>
        Perl
      </TD>
    </TR>
    <TR>
      <TD>
        Template Toolkit
      </TD>
      <TD>
        Just Templates
      </TD>
      <TD>
        Pipeline
      </TD>
      <TD>
        Compiled
      </TD>
      <TD>
        Mini-Language
      </TD>
    </TR>
    <TR>
      <TD>
        Apache::ASP
      </TD>
      <TD>
        Framework
      </TD>
      <TD>
        Callback
      </TD>
      <TD>
        Compiled
      </TD>
      <TD>
        Perl and XSL
      </TD>
    </TR>
    <TR>
      <TD>
        HTML::Embperl
      </TD>
      <TD>
        Framework
      </TD>
      <TD>
        Callback
      </TD>
      <TD>
        Compiled
      </TD>
      <TD>
        Perl
      </TD>
    </TR>
    <TR>
      <TD>
        SSI
      </TD>
      <TD>
        Just Templates
      </TD>
      <TD>
        Callback
      </TD>
      <TD>
        Repeated Parse
      </TD>
      <TD>
        Mini-Language
      </TD>
    </TR>
    <TR>
      <TD>
        AxKit
      </TD>
      <TD>
        Framework
      </TD>
      <TD>
        Pipeline
      </TD>
      <TD>
        Compiled or Cached Parse Tree
      </TD>
      <TD>
        Perl and XSL and Mini-Language(s)
      </TD>
    </TR>
    <TR>
      <TD>
        HTML::Template
      </TH>
      <TD>
        Just Templates
      </TD>
      <TD>
        Pipeline
      </TD>
      <TD>
        Cached Parse Tree
      </TD>
      <TD>
        Mini-Language
      </TD>
    </TR>
    <TR>
      <TD>
        Text::Template
      </TD>
      <TD>
        Just Templates
      </TD>
      <TD>
        Pipeline
      </TD>
      <TD>
        Compiled
      </TD>
      <TD>
        Perl
      </TD>
    </TR>
  </TABLE><P>
  <HR>
  <H1><A NAME="updates">Updates</A></H1>
  <P>These modules are moving targets, and a document like this is bound to
  contain some mistakes.  Send your corrections to <A HREF="mailto:perrin@elem.com.">perrin@elem.com.</A>
  Future versions of this document will be announced on the mod_perl
  mailing list, and possibly other popular Perl locations as well.</P>
  
  </BODY>
  
  </HTML>
  
  
  

Mime
View raw message