in reply to I am about to write my very own templating module..
<aol mode="on">me too!</aol>
The fact that TT2 or HTML::Template support elaborate constructs doesn't mean that you have to use them. You can perfectly decide not to use anything else than simple variable interpolation and loops. This is really the core of the Perl spirit by the way: you get enough rope to hang yourself and half of the town with you, but you can decide not to use it. Perl let you decide how to use the language, advanced templating systems let you decide how much you want to put in the template.
I personally use Text::Template, and I mostly use interpolation and loops like foreach (@item) { $OUT .= "<td>$_</td>"; }.
That said, if you want to improve a module so looping over complex data structures becomes easier, by all means go for it!
Here is an example of a function for Text::Template, that will return a list as an HTML line. You could write a bunch of those functions, then have them loaded from a separate file through prepend or always_prepend.
#!/bin/perl -w use strict; use Text::Template; @T::list= qw( foo bar baz); my $template = new Text::Template (TYPE => 'FILEHANDLE', SOURCE => \*D +ATA ); print $template->fill_in( PACKAGE => 'T'); __DATA__ {sub table_line { $OUT .= "<tr>"; foreach (@_) { $OUT .= "<td>$_</td>"; } $OUT .= "</tr>"; } } simple list:{table_line( @list);}
This is just a (probably lame!) example, but I just want to stress that writing Yet Another Module might look glamourous, but if you want your code to be really useful (and used), modifying an existing module might be a better idea.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: I am about to write my very own templating module..
by ajt (Prior) on Sep 26, 2001 at 13:33 UTC | |
by perrin (Chancellor) on Sep 27, 2001 at 08:49 UTC |