http://www.perlmonks.org?node_id=139931


in reply to Refactor method calls or not?

I like dragonchild's answer, but here is yet another way:
# untested sub add_company { return gen_add('company',@_); } sub add_financial_diary { return gen_add('financialDiary',@_); } sub gen_add { my ($table,$self,$data) = @_; my $return = $self->_generic_insert( $data, $table ); $self->{ _dbh }->commit if ! $self->{ _error }; return $return; }

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)

Replies are listed 'Best First'.
Re: (jeffa) Re: Refactor method calls or not?
by japhy (Canon) on Jan 19, 2002 at 00:35 UTC
    The corollary to that, which uses autoloading, is:
    { my %calls = qw( company company financial_diary financialDiary ); AUTOLOAD { my ($meth) = $AUTOLOAD =~ /.*::(.*)/; if (my $table = $calls{$meth}) { *{"add_$meth"} = sub { my $self = shift; $self->gen_add($table, @_); }; goto &{"add_$meth"}; } require Carp; Carp::croak "Unknown table action '$meth'"; } }

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;