Front page | perl.perl6.language |
Postings from June 2001
Re: Multiple classifications of an object
From:
Michael G Schwern
Date:
June 27, 2001 16:43
Subject:
Re: Multiple classifications of an object
Message ID:
20010626154948.A23874@blackrider
On Mon, Jun 25, 2001 at 11:36:34PM +0200, Trond Michelsen wrote:
> The downside is of course that I need to make a small stub for every
> single function I want to delegate.
Well, that's relatively simple to automate...
%Delegations = ( foo => '_This',
bar => '_This',
yar => '_That',
);
while(my($meth, $key) = %Delegations) {
*{$meth} = sub {
my($self) = shift;
$self->{$key}->$meth(@_);
};
}
So $obj->foo(@args) becomes $obj->{_This}->foo(@args). Ahh, the magic
of closures.
Wasn't Damian working on something like this? I looked at his
delegation stuff in perl5+i, but it didn't seem to have anything to do
with this sort of delegation.
--
Michael G. Schwern <schwern@pobox.com> http://www.pobox.com/~schwern/
Perl6 Quality Assurance <perl-qa@perl.org> Kwalitee Is Job One
<purl> Hey Schwern! honk, honk, honk, honk, honk, honk, honk, honk,
honk, honk, honk, honk, honk, honk, honk, honk, honk, honk, honk,
honk, honk, honk, honk, honk, honk, honk, honk, honk, honk, honk,
honk, honk, honk, honk, honk, honk, honk, honk, honk, honk, honk,
honk, honk, honk, honk, honk, honk, honk, honk, honk, honk!