basically, i have a handful of routines that pull values out of a database and create an anon array of hashrefs to pass into HTML::Template:
and so on.sub _getBuilderList { my $self = shift; my $selection = shift; my $sth = $self->param('DBH')->prepare("SELECT id, buildername + FROM builder ORDER BY buildername" ); $sth->execute(); my $cities; while ( my $row = $sth->fetchrow_hashref() ) { $row->{SELECTED}++ if $row->{id} == $selection; push @$cities, $row; } return $cities; } sub _getSchoolList { my $self = shift; my $selection = shift; my $sth = $self->param('DBH')->prepare("SELECT schoolname FROM + school ORDER BY schoolname" ); $sth->execute(); my $cities; while ( my $row = $sth->fetchrow_hashref() ) { $row->{SELECTED}++ if $row->{schoolname} eq $selection +; push @$cities, $row; } return $cities; } sub _buildGenericSelect { my ( $self, $max, $selection ) = @_; my $array; foreach my $number ( ( 1 .. $max ) ) { my $row; $row->{VALUE} = $number; $row->{SELECTED}++ if $number == $selection; push @$array, $row; } return $array; }
the end result is a select menu using the anon array as a TMPL_LOOP
some of them use name as the option value, others use a numeric value ... ( the data's a mess, but it's coming from another datasource ... )
i wonder if there's a quicker way to do it (rather than to keep creating a new 'accessor' every time.
In reply to abstraction -- level up! by geektron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |