note
metaperl
<blockquote>Imagine a page with 20 variables. The templates look almost exactly the same for Petal and Seamstress but Seamstress also requires 40 almost identical lines of Perl to find the ids and replace them.</blockquote>
Actually, I believe your assessment is based on my slow, plodding
examples which dont use the convenience methods in
[cpan://HTML::Element::Library]. Please take a look at
that library module, in particular the <code>content_handler</code>
subroutine and then understand that the Seamstress code can be
quite concise.
In
fact, even without looking at that, did you notice my
second way of rewriting the example? I did not use the id tag
from the HTML more than once in the Seamstree code. I repeat:
<code>
# look ma, concise code!
for my $content (qw(name last_login)) {
$tree->look_down('tal:content' => $content)
->replace_content($hash->{user}{$content});
}
</code>
<blockquote>This means that each ID tag has to appear twice, once in
the template and once in your Perl, plenty of opportunity for
typos.</blockquote>
I have the same thing in both places: an id tag. Petal has a data
structure in one place and a mini-language to drive access to the
data structure in the other. Typos happen. Test suites catch
them. Both frameworks have things to do in Perl and HTML.
<blockquote>Lets say you decide that your template should display a field that was previously omitted. Now you have to change your template _and_ add 2 more lines of Perl to make sure it gets replaced.
</blockquote>
And with Petal, you have to go retrieve the field again and make sure
that the
access of the field syncs up with TAL specifier. We both have to
do work and again you overstate the number of code lines due to
lack of familarity with convenience libraries.
<P>
And at some point, you are going to have to go into the HTML and do
your mini-programming. I _never_ have to touch the HTML as long
as the designer puts an id tag wherever dynamic functionality is
needed.
<P>
<blockquote>At which point I'd have basically invented the main part
of TAL. Mini-languages are bad but I'll take a small, tight
mini-language any day over lines and lines of cookie cutter
coding.</blockquote>
Perl is a powerful general purpose programming language offering
numerous facilities for re-use: hashes,
subs, modules, objects, normalized database
access, etc. Writing cookie-cutter code in _any_ domain is
un-necessary if you know Perl and have a background in software
engineering. The codebase of Seamstress in the
<a href=http://www.gimblerus.com>online website I just
developed</a> does not suffer from your proposed weakness.
<P>
Further, when the unrolling tasks becomes more difficult, such
as moving around div elements or adding 2 or 3 attributes to an
element based on complex business logic, I expect the
mini-language to peter out or resort to PERL tags while my
end-to-end Perl approach
will continue to support me even at such higher levels of
dynamic HTML munging.
<P>
At any rate, [cpan://Petal] and [cpan://Seamstress] and
[cpan://XML::LibXML] all stress
non-invasive HTML templating. And any of the 3 is hugely
preferred over any other existing approaches for me.
<P>
And don't forget: Seamstress is not alone! It has a
<a href=http://xmlc.enhydra.org> counterpart in the Java world</a>
named XMLC. And I must thank Chris Winters, the person who
initially pointed this framework out to me.
<P>
Nice discussion. Thanks for your input!
433729
433923