in reply to abstraction -- level up!

Well one step to simplifiy that would be to use selectall_array($sql, {Slice => {}}) and then one of your subs becomes:

sub _getBuilderList { my $self = shift; my $selection = shift; my @cities = $self->param('DBH')->selectall_array("SELECT id, +buildername FROM builder ORDER BY buildername", {Slice => {}} ); @cities = grep { $_->{SELECTED}++ if $_->{id} == $selection; $ +_ } @cities; return \@cities; }
Something along those lines at least. Then you see your just passing a SQL statment and you have a condition for selection. I'm not sure if if can be reduced any but this is a nice reduction so far.


___________
Eric Hodges

Replies are listed 'Best First'.
Re^2: abstraction -- level up!
by geektron (Curate) on Jun 16, 2004 at 18:13 UTC
    hmmm ... i was thinking more about not having to build each little accessor sub over and over.

      But why would you have to? Just pass in the SQL and the selected id:

      sub make_select { my ($dbh, $sql, $args, $id) = @_; my $items = $dbh->selectall_arrayref($sql, {Slice => {}}, $args); for ($items) { $_->{selected} = 1 if $_->{id} == $id; } return $items; }

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
        well, i guess a function more like this ... passing SQL into it, would do the trick. (along with the name of the possible selected value, since in some cases it's ID, others it's NAME, etc )

        something in me just says that passing around SQL is a bad idea. i don't know why... it's a gut feeling about later maintainability.