####
####
sub _getBuilderList {
my $self = shift;
my $sth = $self->param('DBH')->prepare("SELECT id, city_name FROM city
ORDER BY city_name" );
$sth->execute();
# returns a reference to an array of hash refs
my $cities= $sth->fetchall_arrayref( {} );
$sth->finish;
return $cities;
}
####
my $city_list= $self->_getBuilderList;
# ...
my $template= $self->load_tmpl( ... );
$template->param(
cities => $city_list,
# ...
);
require HTML::FillInForm;
return HTML::FillInForm->new->fill(
scalarref => \$template->output,
fobject => $self->query,
);
####
$self->query->param( city_id => $some_value );
# HTML::FillInForm code as before
####
sub _getBuilderList {
my $self = shift;
my $sql = q{
SELECT id, city_name
FROM city
ORDER BY city_name
};
return selectall_sql( $self->param('DBH'), $sql );
}
# (needs proper error handling)
sub selectall_sql {
my( $dbh, $sql, $values )= @_;
$values ||= [];
my $results= $dbh->selectall_arrayref(
$sql,
{ Slice => {} },
@$values
);
return $results if $results;
warn $dbh->err if $dbh->err;
return;
}