Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: method dispatch question

by polettix (Vicar)
on Jul 09, 2008 at 16:10 UTC ( #696486=note: print w/ replies, xml ) Need Help??


in reply to method dispatch question

Once you have a reference to a method, the following notations are perfectly equivalent:

$mref->($self); # OR $self->$mref();
In this case, in fact, usual OOP stuff for hereditariness does not kick in, because perl already has a method to call.

I agree with moritz about avoiding syntaxes that go beyond readability. On the other hand, I think that the following remains inside the realm of readability:

$self->get_mref(...)->($self);
although I'd probably go for a temporary variable anyway, just to stress the fact that you're getting a method to call on $self.

perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Io ho capito... ma tu che hai detto?


Comment on Re: method dispatch question
Select or Download Code
Re^2: method dispatch question
by ysth (Canon) on Jul 10, 2008 at 09:52 UTC
      But does that matter when all the arguments are there (other than OO based things, like inheritance & polymorphism, not working obviously)?
        Inheritance and polymorphism wouldn't work anyway because the method to call has already been established. I think that ysth's point is that the two forms are not 100% equivalent, because there's some means to tell them apart. This seems to privilege the $object->$method() notation over the other IMHO.

        Whether this information will ever be used is something that only the particular implementation will be able to tell, but I'd inclined to think that in the vast majority of cases the two forms are interchangeable without any problem. But I'm eager to see comments contradicting this statement!

        perl -ple'$_=reverse' <<<ti.xittelop@oivalf

        Io ho capito... ma tu che hai detto?
        Potentially. Search perlmonks for called_as_method and you'll see it given as the answer to requests for "how do I make my sub do something different when called as a method"?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://696486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-10-20 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (72 votes), past polls