sub start {
my $webapp = shift;
my $drink_types = $webapp->get_drink_types;
return $webapp->drink_menu($drink_types);
}
sub get_drink_types {
my $webapp = shift;
my $dbh = $webapp->param('dbh');
# Get data from database
my $types =
$dbh->selectcol_arrayref('select distinct type from drinks')
|| die "Database error: $DBI::errstr";
return $types;
}
sub drink_menu {
my ($webapp, $types) = @_;
# Build array of values for template
my @drinks;
foreach my $drink (@$types) {
push @drinks, { label => $drink, value => $drink };
}
my $template = $webapp->load_tmpl('drink_type.tmpl')
|| die "error loading tmpl";
# Fill template variables
$template->param(DRINK_TYPES => @drinks);
return $template->output;
} |