in reply to Reference to a method within Object::InsideOut/parent class
Obviously, I should be able to replace the anonymous subroutine with a straight reference to set_foo.
But then you wouldn't have the object to call set_foo upon. If that's desirable (e.g. set_foo is a class method) then you can reference it with \&Fooclass::set_foo. But it sounds like it's an object method, so you'll need the object to call it on.
If you have the object available outside of your dispatcher's anon subs, then you can just use the actual method name:
my %dispatcher = ( foo => 'set_foo', bar => 'set_bar' ); my $method = $dispatcher{$code}; $self->$method( $parameter );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Reference to a method within Object::InsideOut/parent class
by dhosek (Beadle) on Jul 06, 2008 at 17:20 UTC |
In Section
Seekers of Perl Wisdom