roman has asked for the wisdom of the Perl Monks concerning the following question:
Experienced monks,
i am about to do some web programming in Perl, so I started to learn about Catalyst and MVC. I have some previous experience with HTML::Mason, but Catalyst uses Template::Toolkit as the first option for view components.
Why? Why is it worth to use (and learn) a different language for the template? I ask, I don't argue, because obviously many people dot it and someone even presented TT as a standard tool for web page development at Vienna.pm lightning talks.
So far I found only 3 reasons hardly applicable in our environment:
- It is language (Perl) independent. Which seems of no concern for me, since we develop all of our application in Perl (or PL/SQL :-)).
- It is safer, since the template developer has no access to naked Perl. It also seems of no concern because the template developer is me or my office mate.
- Different template languague supports the separation of the view from the model and controller. It seems a bit academic for me now.
Am I wrong? Is there any other - sound and general reason to prefer TT from Mason?
But even If HTML::Mason is the appropriate choice for my environment I can go a bit further. Why to use ANY template engine at all? Why don't use ordinary Perl for the view components?
Everytime I tried a template based development (Perl + HTML::Mason and a bit of PHP + Smarty) I ended up with quite a messy template with lots of iterations and conditions intertwined with plain text.
Where is the advantage of mason template:
<table> <tr><th>Title</th><th>Rating</th><th>Author(s)</th></tr> % for $book (@books){ <tr> <td><% $book->title %></td> <td><% $book->rating %></td> <td> <%perl> my @authors = $book->authors; </%perl> (<% scalar @authors %>) <% join(', ', @authors) %> </td> </tr> %} </table>
over Perl code (I use fictional function-to-html interface, I believe there must be plenty of them)?
print html_table( html_tr( html_th('Title'), html_th('Rating'), html_th('Authors'), ( map { my $book = $_; html_tr( html_td( $book->title ), html_td( $book->rating ), html_td( do { my @authors = $book->authors; scalar(@authors) . ' ' . join( ', ', @auth +ors ); } ) ); } @books ) ) );