in reply to Skipping the middle man & the SUPER gotcha

The "::" makes it look like a procedural interface call, but it is a bona fide OO method call, with an implicit instance (or package name) as first argument and all; a rather different animal from the similar-looking (and wrong) Grandpa::hello().

I think that:

$me->Grandpa::hello()

is the same as:

Grandpa::hello($me);

which isn't OO. You can test it like so:

use strict; package other; sub hello { print "otherwise @{[ref shift]}\n"; } package Grandpa; sub hello { my $class = ref $_[0] || $_[0]; print "How do you do, from $class.\n"; } package Dad; our @ISA = 'Grandpa'; sub hello { my $class = ref $_[0] || $_[0]; print "Hiya from $class!\n"; } package Me; our @ISA = 'Dad'; sub new { bless {} } sub hello { print "hello\n"; } package main; my $me = bless {}, 'Me'; # look Ma, no constructor! $me->Grandpa::hello; $me->other::hello; __END__ How do you do, from Me. otherwise Me

hth

Replies are listed 'Best First'.
Re^2: Skipping the middle man & the SUPER gotcha
by merlyn (Sage) on Apr 02, 2005 at 17:05 UTC
    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.

      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.