Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

->SUPER::hi relies on __PACKAGE__ ? (monkeypatching) Can't locate object method "hi" via package "main::SUPER"

by Anonymous Monk
on Jun 13, 2013 at 01:36 UTC ( [id://1038647]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

->SUPER::hi relies on __PACKAGE__ ? (monkeypatching) Can't locate object method "hi" via package "main::SUPER"

So I was monkeypatching and I tried to SUPER::method and I got

$ perl @HUH::ISA=q{FOO}; @FOO::ISA=q{BAR}; sub BAR::hi{66} sub FOO::hi { shif +t()->SUPER::hi }; print HUH->hi; __END__ Can't locate object method "hi" via package "main::SUPER" at - line 1.

I guess it SUPER:: relies on __PACKAGE__

I didn't know that

Replies are listed 'Best First'.
Re: ->SUPER::hi relies on __PACKAGE__ ? (monkeypatching)
by Athanasius (Archbishop) on Jun 13, 2013 at 02:19 UTC

    Yes. See “How SUPER is Resolved” in perlobj#Inheritance:

    The SUPER pseudo-class is resolved from the package where the call is made. It is not resolved based on the object’s class. This is important, because it lets methods at different levels within a deep inheritance hierarchy each correctly call their respective parent methods.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: ->SUPER::hi relies on __PACKAGE__ ? (monkeypatching) Can't locate object method "hi" via package "main::SUPER"
by tobyink (Canon) on Jun 13, 2013 at 06:54 UTC

    Yes, SUPER:: relies on __PACKAGE__. But you can always provide an explicit package name in your super call...

    @Bar::ISA = qw(Foo); sub Bar::xxx { my $self = shift; warn "Bar::xxx called"; return $self->Foo::xxx(@_); # instead of SUPER::xxx }
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: ->SUPER::hi relies on __PACKAGE__ ? (monkeypatching) Can't locate object method "hi" via package "main::SUPER"
by choroba (Cardinal) on Jun 13, 2013 at 07:41 UTC
    See also SUPER.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I wonder why SUPER has never implemented an AUTOLOAD mechanism for a 'super' package so you can do something like $obj->super::method (i.e. super package access at run time with a similar syntax).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-03-29 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found