Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: goto superclass method

by Aristotle (Chancellor)
on Dec 22, 2004 at 21:49 UTC ( [id://416921]=note: print w/replies, xml ) Need Help??


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

SUPER:: is always relative to __PACKAGE__, and when you start saying sub Foo::bar, the __PACKAGE__ doesn't change to Foo, so you have a problem with SUPER.

That's wrong.

#!/usr/bin/perl use strict; use warnings; package Foo; sub bar { } package Baz; our @ISA = qw( Foo ); sub bar { my $self = shift; print $self->SUPER::can( "bar" ), "\n"; print $self->can( "SUPER::bar" ), "\n"; }; package main; print UNIVERSAL::can( Baz => "bar" ), "\n"; Baz->bar; __END__ CODE(0x815a230) CODE(0x815a230) CODE(0x813bc4c)

Interestingly enough, I thought I had tried the $self->can( "SUPER::foo" ) combination, but apparently I didn't. Huh.

Makeshifts last the longest.

Replies are listed 'Best First'.
•Re^4: goto superclass method
by merlyn (Sage) on Dec 22, 2004 at 23:19 UTC
    Huh? Your example shows that both UNIVERSAL::can and SUPER::can on asking how a "Baz" can "bar" return the same code (which is Baz::bar), and that SUPER::bar for Baz is in fact the one in Foo::bar.

    That's exactly what I said. You didn't show "wrong" on anything. Did you mean something else?

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

      You claimed the current __PACKAGE__ affects the result of Foo->SUPER::can( 'bar' ):

      when you start saying sub Foo::bar, the __PACKAGE__ doesn't change to Foo, so you have a problem with SUPER.

      I posted code where changing packages, and thus __PACKAGE__, is inconsequential, contrary to your claim.

      So the reasoning in my initial post about why the goto there is an infinite loop is correct.

      Makeshifts last the longest.

        You claimed the current __PACKAGE__ affects the result of Foo->SUPER::can( 'bar' )
        Nothing of the kind. Why do you keep saying SUPER::can? 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.

        Please go back and reread what I wrote. It's still true, and your example doesn't show anything to the contrary. I said that SUPER:: is affected by __PACKAGE__, and __PACKAGE__ is not affected by the package name of the subroutine, but only by package directives. Your "infinite" loop is for reasons other than what you state, because your hypothesis is incorrect.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-20 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found