sub _select_fields
{
my $self = shift;
my %rev_types = (
both => sub {
# some difficult logic
},
total => sub { [qw/foo bar/] },
);
my $rev_type = $self->request->param('rev_type');
$rev_type = 'both' unless exists $rev_types{$rev_type};
return @{$rev_types{$rev_type}->()};
}
Though as noted above, the $rev_types should probably be moved outside of the sub.
If necessary, you can also write some code for generating a hash key based upon the difficult logic. This has the advantage of cleanly encapsulating the logic for each case rather than embedding it in the if/elsif/else constructs.
|