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

benh ben.hengst at gmail.com
Mon Jul 23 17:29:14 PDT 2007


ok heres the issue. I have two modules, one that is a book info look
up module(BookInfo), and one that is more of a basic model for a
single book(SingleBook). SingleBook holds an instance of BookInfo so
that it can make many of it's lookups (BookInfo->{bi}). All of the
methods for BookInfo take an isbn as the param, SingleBook takes an
isbn as a param for new, and holds it.

The problem that I can't cleanly subclass BookInfo, because I already
know my isbn, so
I'm running in to is I keep haveing stubs that just pass thru to
BookInfo in SingleBook. About 2/3's of SingleBook is basicly

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.

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?';
}

... but I would have no idea where to plug this in to intercept every
call to this object, unless I build a sub that EVERYTHING goes thru...
but thats alot of code to change, and again seems like a very cludgy
way to trap things.

Any one have any other ideas? Am I on the right track? Completely
missed the mark?

-- 
benh~


More information about the Pdx-pm-list mailing list