[Pdx-pm] [build in defaults to method calls from the outside] need some help thinking thru this one
A. Pagaltzis
pagaltzis at gmx.de
Wed Jul 25 23:15:32 PDT 2007
* Austin Schutz <tex at off.org> [2007-07-24 08:40]:
> Also in vi it only takes about 3 seconds per additional method
> to add in new methods after a few yypppps:
>
> sub method1 { my($self) = @_; $self->{bi}->method1($self->{isbn}); }
> sub method2 { my($self) = @_; $self->{bi}->method2($self->{isbn}); }
> sub method3 { my($self) = @_; $self->{bi}->method3($self->{isbn}); }
> sub method4 { my($self) = @_; $self->{bi}->method4($self->{isbn}); }
>
> *shrug*. Seems clean to me unless you have a bajillion methods. Ymmv.
#11911 You wrote the same thing twice here. The cardinal rule of
programming is that you never ever write the same thing twice.
* Michael G Schwern <schwern at pobox.com> [2007-07-24 09:00]:
> Also every time BookInfo adds a new method you have to add a
> new method, tightly binding the two classes together.
That statement makes no sense. Of course they’re tightly bound;
one is proxying calls to the other. You don’t want to just proxy
any old that might be available on BookInfo; what if a method is
added whose signature is different from the other methods?
* Austin Schutz <tex at off.org> [2007-07-26 06:55]:
> But I like the explicitness of it only working with specific
> methods. I like my bonds tight. :-)
use Sub::Installer qw( install_sub );
for my $subname ( qw( meth1 meth2 meth3 ) ) {
install_sub {
as => $subname,
code => sub { $_[0]->{bi}->$subname( $_[0]->{isbn} );
};
}
> Come to think of it you could have AUTOLOAD only work on
> specific methods too, I guess that amounts to about the same
> thing without the cut and paste effect.
No need for AUTOLOAD.
--
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hack;
#Aristotle
More information about the Pdx-pm-list
mailing list