in reply to Trying to understand template-foo

Hi jest

You are facing the dilemna which faces every Perl coder who has also to do CGI type scripts. Until recently I generated a lot of my HTML using CGI.pm. But, as you have found, it becomes unwieldy and means that every time you want to change a design element you need to dig into the Perl. So, time for templating.

My feeling is that the design problem should be handled in the design phase and that presentation, should as far as possible, be delegated to the template.

This means that you can then effectively use CSS (Get 'Cascading Style Sheets - The Definitive Guide' by Eric Meyer from O'Reilly and 'Eric Meyer on CSS' by Eric Meyer from New Riders, they are an excellent introduction and reference). By doing this you can almost totally divorce the presentation design from the Perl coding. In my own case, I present a lot of dynamically generated forms that write back to databases. They are all perform the same function but I now have just one Perl script that takes a page template that also loads a form template. I now use one form template which has its presentation controlled by a style-sheet with as many as 30-50 different 'content wrappers' or page templates in any given week. These forms at times handle as many as 50,000 completed forms per week.

To me HTML::Mason is not a templating system, it is a code embedding system which tends to make a Perl programmer feel a lot more like a PHP programmer. I write in Perl becuase I want to write in Perl, not PHP! Mind you, there is nothing wrong with PHP, but why use a silly little band-aid when you can do it properly with duct-tape :)

Using Class::DBI and some of the other DBIx series modules can take a lot of heay out of the whole process. CGI.pm is still very useful glue, CGI::Session gets a good rating in this office also.

I spent a lot of time reading the various documents, there are some useful things on this site in particular and also at least one good paper on the mod_perl site about choosing a templating system. Then I started coding, like you my work is getting stuff into and out of databases using Perl, DBI, MySQL and either HTML or in my case a lot of Tk. Test code some applications in each of the different systems, thats the best way to learn!

But I have achieved almost total separation of presentation and data-processing by using HTML::Template, DBI::Class, CGI.pm and CGI::Session.

Of course, as always, YMMV!

jdtoronto