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


in reply to Refactor method calls or not?

I am going to advocate for creating each method name explicit
for the reason of future change. If you find that method
needs to be changed it will already physically exist and
you will just have to modify it. Now I know it isn't a big deal
to add a method in the future, but if you can do it at this
stage I think you will further ahead in the long run.
I think AUTOLOAD is a bad way to go on this one. I had
a discussion with some other proprammers recently about
using AUTOLOAD on something similar and it frowned upon
for maintenance and speed issues.
If there is code already using these methods I would also
suggest code like this:
sub add_company { my ($self,$data) = shift; $self->gen_add($data,'company'); } sub add_financial_diary { my ($self,$data) = shift; $self->gen_add($data,'financialDiary'); } sub gen_add { my ($self,$data,$table) = @_; my $return = $self->_generic_insert( $data, $table ); $self->{ _dbh }->commit if ! $self->{ _error }; return $return; }
This code would allow you move the gen_add method into
another inherited class if you need to and not break the
code. By having $self and $data available you
also cut down on code that needs to be written if you
determine the method needs to not call the gen_add method.