> [% USE DBI %]
> [% DBI.connect(dsn, specialuser, secretpass) %]
> [% query = DBI.prepare('SELECT * FROM users,other WHERE userid = ?')
> %]
> [% FOREACH user = query.execute(idUserProvided) %]
> [% query.name %]
> [% query.emailaddress %]
> [% END %]
>
> or I can instantiate in perl and the template becomes
> [% user.name %]
> [% user.emailaddress %]
>
> The former is easier to modify (for many people) than the perl that the
> latter would require. If we wanted to show another attribute that
> resides in another linked table - say usersPhoto - then the former
> is simple to change in the template, whereas the latter requires mucking
> around in the perl. But the "business logic" seperation is nicer in the
> latter since the template doesn't have to know anything about the
> database structure...
It's a big question (in-line code vs. MVC) with an answer that depends a bit
on context. If this is a somewhat complex application that you need to keep
running for a while, my advice is to put the logic in perl code, not in the
template. It makes it easier to divide the tasks, and makes for cleaner
code.
I'll be talking about this and related issues in my presentation at The Perl
Conference in July.
- Perrin