Brett> This is, however, off of the point I was shooting for.  I
Brett> know there will be philisophical differences.  I'm mainly
Brett> interested in functional differences.  What does Toolkit
Brett> do that Text::Template doesn't?

Perrin> It doesn't look like you got all of your questions answered.
Perrin> Listing all the features Template provides that Text::Template
Perrin> doesn't would take a long time since it's a very full-featured
Perrin> system, but here are some highlights:
Perrin> [snip]

An excellent list.

My $0.02 is the following.  At the risk of making statements about
Text::Template based only on a short perusal of the documentation
and writing a couple of short examples, here's a key difference:
TT allows you to capture and manipulate text between directives,
whereas I don't see that Text::Template can.  For example, I can't
see that Text::Template can use loops or conditionals around blocks
of text, as in this ePerl example from Perrin:

Perrin> <: if ($product->isbn) { :>
Perrin>   It's a book!
Perrin> <: } else { :>
Perrin>   It's NOT a book!
Perrin> <: } :>

It appears that in Text::Template each perl fragment must be atomic
(ie: can be separately eval'ed) so you can't have loops or conditionals
spanning across fragments.  I can't see any way to manipulate the text
in between the perl fragments.

The philosophy section in the Text::Template pod certainly resonates
with me:

>     Philosophy
>
>     When people make a template module like this one, they
>     almost always start by inventing a special syntax for
>     substitutions.  For example, they build it so that a string
>     like `%%VAR%%' is replaced with the value of `$VAR'.  Then
>     they realize the need extra formatting, so they put in some
>     special syntax for formatting.  Then they need a loop, so
>     they invent a loop syntax.  Pretty soon they have a new
>     little template language.
> 
>     This approach has two problems: First, their little language
>     is crippled. If you need to do something the author hasn't
>     thought of, you lose.  Second: Who wants to learn another
>     language?  You already know Perl, so why not use it?
> 
>     `Text::Template' templates are programmed in Perl.  You
>     embed Perl code in your template, with `{' at the beginning
>     and `}' at the end.  If you want a variable interpolated,
>     you write it the way you would in Perl.  If you need to make
>     a loop, you can use any of the Perl loop constructions.  All
>     the Perl built-in functions are available.

However, I find that TT is a big help in balancing the partitioning
of presentation logic and application logic, and its flexibility and
extensibility more than make up for the disadvantage of a (simple)
new language.

All of these different systems (TT, Text::Template, HTML::Template,
HTML::Mason, embPerl, ePerl etc) all represent different tradeoffs
between power, flexibility, partitioning etc.  Providing more power
(eg: full perl) also presents a bigger burden in providing a clean,
maintainable template API.  There is certainly no universal correct
answer, but TT is the best for our uses.

Craig


Reply via email to