Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^7: goto superclass method

by Aristotle (Chancellor)
on Dec 23, 2004 at 00:14 UTC ( #416964=note: print w/replies, xml ) Need Help??

in reply to •Re^6: goto superclass method
in thread goto superclass method

That's really weird. That's "the can method that isn't in the current class". Unless you've implemented a local "can" method, that's gonna be UNIVERSAL::can.

You mean unless the superclass has implemented a local can method.

In any case, that is of course half my point. You are correct that the SUPER::can in my original example without package statements is relative to main, which I didn't realize. But that doesn't change anything about my claim that it dispatches to UNIVERSAL::can with $_[ 0 ] as the first parameter, which I identified as the cause for the infinite loop.

For some reason, you are saying that this reasoning is incorrect, but you haven't provided an alternative explanation. You then stated that SUPER is relative to the current package, which causes problems with code, although you made no explicit connection between the two facts.

I still don't see how my explanation can be wrong. Assuming no local implementations of can, Bar->SUPER::can( 'foo' ) is equivalent to UNIVERSAL::can( Bar => 'foo' ), which will find Bar::foo if there is one, not the foo in a superclass of Bar, despite the adornment with SUPER:: in the wrong place. And if I'm in Bar::foo to begin with, and goto myself, that's an infinite loop.

Makeshifts last the longest.

Replies are listed 'Best First'.
•Re^8: goto superclass method
by merlyn (Sage) on Dec 23, 2004 at 00:22 UTC
    Well, I think the main reason your code is broken is this:
    goto $_[ 0 ]->SUPER::can( 'method' );
    I have no idea how this even parses, unless it's interpreted as "go to the label that matches the stringification of the result of this expression". You're missing the necessary &{ .. }. So, either that isn't the code you're running, or something Very Weird is going on.

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

      goto seems to do the expected thing when you give it a coderef.

      $ perl -le'my $foo = sub { print "bar" }; sub x { goto $foo } print "$ +foo"; x' CODE(0x813bc08) bar

      I don't think there's any doubt about what's happening here.

      Oh, also, none of my previous examples change at all in behaviour if you use the goto &{ ... } notation instead.

      Makeshifts last the longest.

        Well, then, we're back to my other explanation. You're not calling can("SUPER::bar"). You're calling SUPER::can("bar"), so you're finding yourself. Don't do that. Stop saying SUPER::can. It means practically nothing other than "can", unless you have a "can" method in the current class.

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2023-10-04 16:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found