Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

•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.

Replies are listed 'Best First'.
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).
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


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

    or, assuming that can returned a bound method,
    my $meth_ref = $object->can($method); apply($meth_ref,$arg1,$arg2);

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2016-10-23 04:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (300 votes). Check out past polls.