That's a start, but try breaking it down even further into a command line script that only uses DBI and HTML::Template:
use strict;
use warnings;
use HTML::Template;
use DBI;
my $id = shift || 42;
my $dbh = DBI->connect( ... );
my $tmpl = HTML::Template->new(filehandle => \*DATA);
my $product = $dbh->selectall_arrayref(q{
SELECT image, price, description, serial
FROM product
WHERE id = ?
}, {Slice => {}}, $id);
# i think it's better to use a variable instead of
# passing the results from the query directly to the
# $tmpl->param method (easier debugging)
$tmpl->param(product => $product);
print $tmpl->output;
__DATA__
<tmpl_loop product>
image: <tmpl_var image>
price: <tmpl_var price>
description: <tmpl_var description>
serial: <tmpl_var serial>
</tmpl_loop>
Look into the CPAN test suites for more about that. Test::More, Test::Simple, etc.
|