choosing a templating system

26
Perrin Harkins

Upload: perrin-harkins

Post on 13-Jun-2015

4.894 views

Category:

Technology


2 download

DESCRIPTION

I gave this talk at OSCON 2001. The information here is somewhat outdated, but the related article has been updated since then: http://perl.apache.org/docs/tutorials/tmpl/comparison/comparison.html For the record, this was a really fun talk to give. The title slide had animated flames burning on the screen when people walked in.

TRANSCRIPT

Page 1: Choosing a Templating System

Perrin Harkins

                                                                                                                 

Page 2: Choosing a Templating System

The Ultimate Templating SystemThe Ultimate Templating System

$HTML =~ s/\$(\w+)/${$1}/g;

FOR MORE INFO...

Contact Harkins Enterprises for licensing information. Excellent per-CPU pricing available.

Page 3: Choosing a Templating System

Why bother?Why bother?

Consistency of appearanceReusabilityBetter isolation from changesDivision of labor

Page 4: Choosing a Templating System

Template TaxonomyTemplate Taxonomy

Execution modelLanguageParsingFramework or just templates

Page 5: Choosing a Templating System

Execution ModelExecution Model

Callback– Mason, Embperl, Apache::ASP

mod_perl

Perl space

template

Page 6: Choosing a Templating System

Execution ModelExecution Model

Pipeline– HTML::Template, Template Toolkit

mod_perl Perl space template

Page 7: Choosing a Templating System

CallbackCallback

Pro– Easy to componentize pages– Quick to get started with

Con– Messy for branching

Page 8: Choosing a Templating System

PipelinePipeline

Pro– Handles branching cleanly– Possible tuning opportunities

Con– Slower to get started with

Page 9: Choosing a Templating System

LanguageLanguage

Burn baby burn– in-line Perl– mini-languages

Page 10: Choosing a Templating System

In-line Perl sampleIn-line Perl sample

<% my $product = Product->load('sku' => 'bar1234'); %>

<% if ($product->isbn) { %>

It's a book!

<% } else { %>

It's NOT a book!

<% } %>

<% foreach my $item (@{$product->related}) { %>

You might also enjoy <% $item->name %>.

<% } %>

Page 11: Choosing a Templating System

Mini-language sampleMini-language sample

[% USE product(sku=bar1234) %]

[% IF product.isbn %]

It's a book!

[% ELSE %]

It's NOT a book!

[% END %]

[% FOREACH item = product.related %]

You might also enjoy [% item.name %].

[% END %]

Page 12: Choosing a Templating System

ParsingParsing

CompiledCached parse treeRepeated parse

template Perl codecompiledbytecode

Page 13: Choosing a Templating System

Frameworks vs. Just TemplatesFrameworks vs. Just Templates

URL mappingSession trackingOutput cachingForm handlingDebuggingOther options

– libservlet, Apache::PageKit, OpenInteract, CGI::Application

Page 14: Choosing a Templating System

The ContendersThe Contenders

SSI HTML::Mason HTML::Embperl Apache::AxKit Apache::ASP Text::Template Template Toolkit HTML::Template

Page 15: Choosing a Templating System

SSISSI

CallbackMini-languageRepeated Parse#perlApache::SSI for filtering

Page 16: Choosing a Templating System

HTML::MasonHTML::Mason

Callback (mostly) In-line Perl Compiled Publishing roots<%init> Caching Parameter checking Debug files

Page 17: Choosing a Templating System

Text::TemplateText::Template

CallbackIn-line PerlCompiledSafeIncludes not includedCache it yourself

Page 18: Choosing a Templating System

Apache::ASPApache::ASP

Callback In-line Perl Compiled Built-in objects URL-munging sessions XMLSubs, XSLT

<site:header page="Page Title" /> Sticky widgets Compressed output No RDBMS session storage built in

Page 19: Choosing a Templating System

Apache::AxKitApache::AxKit

Pipeline (usually) Mini-language or in-line Perl Compiled Stylesheet

– XML::XSLT, XML::Sablotron, XPathScript Provider

– XSP, XSP taglibs Caching Compression

Page 20: Choosing a Templating System

HTML::EmbperlHTML::Embperl

Callback In-line Perl Compiled Safe%fdat, %udat HTML support

– TABLE, INPUT, query strings, etc. EmbperlObject Control structures

Page 21: Choosing a Templating System

Template ToolkitTemplate Toolkit

Pipeline (sorta) Mini-language Compiled Dot notation: foo.bar.baz Macros Filters Plugins

– XML, DBI– Dates, prices, multi-column

ttree, Splash library

Page 22: Choosing a Templating System

HTML::TemplateHTML::Template

PipelineMini-languageCached Parse TreeFast and simpleTemplates can be cached in shared

memory or disk

Page 23: Choosing a Templating System

Honorable mentionsHonorable mentions

ePerlApache::XPPCGI::FastTemplateHTML_Tree

Page 24: Choosing a Templating System

PerformancePerformance

Don’t start with your templating system!

Benchmarks– http://www.chamas.com/bench/hello.tar.gz

CGI concerns

Page 25: Choosing a Templating System

Frameworkor Just Templates

Pipeline or Callback

Parsing Method Language

HTML::Mason Framework Callback Compiled Perl

Template Toolkit Just Templates Pipeline Compiled Mini-language

Apache::ASP Framework Callback Compiled Perl

HTML::Embperl Framework Callback Compiled Perl

SSI Just Templates Callback Repeated Parse Mini-language

AxKit Framework Pipeline Compiled or Cached Parse Tree

Perl and XSL and Mini-Language(s)

HTML::Template Just Templates Pipeline Cached Parse Tree

Mini-language

Text::Template Just Templates Callback Compiled Perl

Page 26: Choosing a Templating System

UpdatesUpdates

Article to be published on mod_perl list.

Send corrections to:

[email protected]