On Thu, Aug 23, 2001 at 11:45:45AM -0400, Perrin Harkins wrote:
> If you're talking about the DBI plugin, Apache::DBI should make your
> connections persistent without any extra work. Personally, I think it's
> better to do your DBI work up front before you run the template, rather than
> using the plugin.
I agreed with Perrin. The DBI plugin is for hacking quick solutions but
it's no substitute for a proper data abstraction.
One approach that I favour is to create your own little data abstraction
layer. It can be very simple, implemented as a hash array, a few
subroutines, or an object or two, or it can be as complicated as you
like with SQL queries on demand, fancy caching and various other
magical delights.
myorg => {
name => 'My Organsisation',
employees => [ me, you, him, ... ],
products => sub { .... },
...
}
or
package MyOrg;
sub new {
my $class = shift;
bless {
name => 'My Organisation',
}, $class;
}
sub products {
my $self = shift;
$self->_do_some_gnarly_SQL_magic();
....
}
Write your templates to the data interface and forget the rest.
[% FOREACH p = myorg.products %]
If it works out best to pre-fetch all your data and populate a
'myorg' hash then you can do that. Or if 'products' needs to
perform an SQL query to fetch some data then you can do that.
You can change your mind as often as you like, but you shouldn't
need to change your templates.
HTH
A