[Pdx-pm] [build in defaults to method calls from the outside] need some help thinking thru this one

Eric Wilhelm scratchcomputing at gmail.com
Mon Jul 23 23:55:28 PDT 2007

# from benh
# on Monday 23 July 2007 05:29 pm:

>sub do_something {
>   my ( $self ) = @_;
>   return $self->{bi}->do_something($self->{isbn});
>It works, but it seems needlessly messy. What I would like to do is to
>have some way to specify that all calls made to SingleBook that dont
>exits should then get passed to BookInfo with the know isbn.

You could do it with AUTOLOAD, but if you *can* declare the keys, that's 
probably better.  That is, make a list and generate all of the methods 
at compile-time.

You could even use Class::Accessor or Class::Accessor::Classy and just 
declare the getter.


>I was thinking of doing something along these lines:
>if ($self->can($action) ) {
>   return $self->$action;
>} elseif ($self->{bi}->can($action) {
>   return $self->{bi}->$action($self->{isbn});
>} else {
>   die 'freakout... why are we here?';

Though you should consider giving $self->{isbn} to $self->{bi}, provided 
that can be done without staleness.  Of course, I'm just itching to 
apply object-oriented functional programming to something, so why not 
curry it into some object methods?

"...the bourgeoisie were hated from both ends: by the proles, because
they had all the money, and by the intelligentsia, because of their
tendency to spend it on lawn ornaments."
--Neal Stephenson

More information about the Pdx-pm-list mailing list