in reply to Re: Skipping the middle man & the SUPER gotcha
in thread Skipping the middle man & the SUPER gotcha

I think that:
You think that, but you think wrongly. {grin}

If you have an arrow in your syntax (method call), it respects @ISA (keep searching if subroutine is not found) and unshifts the additional first parameter (class name or instance reference). If you don't have an arrow, you don't get that, because it's an ordinary subroutine call. So those are definitely not the same.

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

  • Comment on Re^2: Skipping the middle man & the SUPER gotcha

Replies are listed 'Best First'.
Re^3: Skipping the middle man & the SUPER gotcha
by Thelonious (Scribe) on Apr 02, 2005 at 19:40 UTC
    O Guru,

    If the method name is fully-qualified, how could @ISA be used to any effect? When using a fully-qualified method name, doesn't that routine get called regardless of what's in @ISA? (The "other" package isn't in @Me::ISA, in my example above, and yet &other::hello() gets called, and with $me as an argument.)

    -- A Humble Grasshopper

      No, with the arrow notation, the extra class information just tells it where to start looking in the class hierarchy. It's only identical to a sub call if the method in question is actually found in the class you named.
        Thanks for that. It's clear now, and suprising!

        It doesn't even matter what package the invocant is blessed into, or even if it's an arbitrary bare word.

        use strict; use warnings FATAL => 'all'; package Base; sub hello { print __PACKAGE__.": @{[ref $_[0] || $_[0]]}\n"; } package Kid; our @ISA = 'Base'; package Main; sub hello { print __PACKAGE__.": @{[ref $_[0] || $_[0]]}\n"; } package main; our @ISA = 'Main'; my $main = bless {}; $main->Kid::hello; # Base: main $main->hello; # Main: main __PACKAGE__->hello; # Main: main BareWord->Kid::hello; # Base: BareWord