Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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

by TimToady (Parson)
on Apr 12, 2004 at 19:10 UTC ( #344483=note: print w/replies, xml ) Need Help??

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

From the viewpoint of Perl 5, it's a feature, but from the viewpoint of Perl 6, it's a bug. Perl 6 will distinguish AUTOMETH from AUTOSUB. (Those are the declarative forms, which return references. Perl 6 will distinguish those from the defining forms, which are spelled AUTOMETHDEF and AUTOSUBDEF, and which may only be called on predeclared (or autodeclared) names to supply a missing definition.)

Replies are listed 'Best First'.
•Re: Re: •Re: Detecting function vs method in an AUTOLOAD?
by merlyn (Sage) on Apr 12, 2004 at 19:19 UTC
    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.

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

      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://344483]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2017-05-30 10:24 GMT
Find Nodes?
    Voting Booth?