Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Reference to a method within Object::InsideOut/parent class

by friedo (Prior)
on Jul 06, 2008 at 04:41 UTC ( #695787=note: print w/replies, xml ) Need Help??

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
    Yeah, I supose what I can do is have two hashes, since I also need to do some more complicated processing for some of the dispatches.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://695787]
[LanX]: new Firefox + cb sidebar do random auto expand on submit
[LanX]: probably need to start pm discussion
[LanX]: they have a constitutional referendum in turkey, kind of "do you want a dictator" and everybody opting no gets problems ...
[Corion]: LanX: Random Auto Expand?
[Corion]: LanX: Well, everybody opting "yes" will also get problems. The question is more like "Do you want problems now or problems later?"
[LanX]: and the AA had posters with a big say NO with a small "to alcohol"
[ambrus]: LanX: is it the kind of free and secret vote where there's only one box you can check?
[LanX]: no two boxes , enemies of the state are just denounced

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2017-03-27 12:18 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.