i'm getting sick of creating almost the same subroutines over and over again, but the details *seem* different enough that i can't quite get away with AUTOLOAD ... and the immediate new level of abstraction (that I can see) would require a configuration hash ... a step i don't think really helps.

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:

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; }
and so on.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.