Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

(jeffa) Re: Refactor method calls or not?

by jeffa (Bishop)
on Jan 18, 2002 at 23:53 UTC ( #139931=note: print w/replies, xml ) Need Help??


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:??;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://139931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2021-04-22 23:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?