knight has asked for the wisdom of the Perl Monks concerning the following question:
The user has access to the specific foo_a() and foo_b() methods, or can use foo() to call whatever's registered as the current underlying method.sub foo_a { my ($self, $arg) = @_; # method A for processing $arg } sub foo_b { my ($self, $arg) = @_; # method B for processing $arg } sub foo { my ($self, $arg) = @_; $self->{'foo_code'}->($self, $arg); # XXX } sub foo_set { my ($self, $code) = @_; $self->{'foo_code'} = $code; }
Is there any magic I'm overlooking that cleans this up?$obj->foo_set(sub { # process $_[1] });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: cleaning up an indirect
by chromatic (Archbishop) on Aug 28, 2000 at 20:40 UTC | |
|
RE: cleaning up an indirect
by johannz (Hermit) on Aug 29, 2000 at 02:20 UTC | |
|
RE (tilly) 1: cleaning up an indirect
by tilly (Archbishop) on Aug 28, 2000 at 20:36 UTC | |
|
Re: cleaning up an indirect
by merlyn (Sage) on Aug 28, 2000 at 20:17 UTC |