Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

•Re: Re: •Re: Detecting function vs method in an AUTOLOAD?

by merlyn (Sage)
on Apr 12, 2004 at 19:19 UTC ( #344487=note: print w/ replies, xml ) Need Help??


in reply to Re: •Re: Detecting function vs method in an AUTOLOAD?
in thread Detecting function vs method in an AUTOLOAD?

So, there'll be ways to "fake" a method call using a subroutine call, like we have now? There'll have to be, or else you can't get Perl5 semantics inside Perl6 syntax, as promised.

For example, this should still work, somehow:

my $meth = $object->can("foo"); $meth->($object, $arg1, $arg2); # simulate $object->foo($arg1, $arg2);

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.


Comment on •Re: Re: •Re: Detecting function vs method in an AUTOLOAD?
Download Code
Re: •Re: Re: •Re: Detecting function vs method in an AUTOLOAD?
by Corion (Pope) on Apr 12, 2004 at 19:25 UTC

    Even today, in Perl5, I'd write that as

    $object->$meth($arg1,$arg2);

    but it's clear that one or the other should be there, and not something ugly like

    apply($object,$method,$arg1,$arg2);
    or, assuming that can returned a bound method,
    my $meth_ref = $object->can($method); apply($meth_ref,$arg1,$arg2);
Re: •Re: Re: •Re: Detecting function vs method in an AUTOLOAD?
by TimToady (Parson) on Apr 12, 2004 at 19:55 UTC
    Yes, once you've taken a reference to a method, it's essentially a sub ref at that point, so the Perl 6 equivalent of your code works as you'd expect. In fact, the standard dispatchers are defined in those terms. But the standard dispatchers will be able to keep subs and methods straight to the extent that you wish them to (which, by default, is up to the point that a method turns out to be completely missing, and you wish it to "failover" to looking for a multi-sub instead).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-08-20 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (110 votes), past polls