in reply to Inheritance via class::derived_method Question

So, the inheritance mechanism does not work for this?

The 'inheritance mechanism' is the  -> operator, which is used in
    Horse->speak();
but entirely absent (and so cannot work) in
    Horse::speak("Horse");
which is an invocation of the  Horse package's  speak subroutine, which is undefined in the OPed example.

Replies are listed 'Best First'.
Re^2: Inheritance via class::derived_method Question
by ikegami (Patriarch) on Nov 18, 2010 at 22:55 UTC

    The 'inheritance mechanism' is the -> operator,

    No. The inheritance mechanism applies to method calls. Few of the -> operators have anything to do with methods. For example,

    $x->[0]

    Furthermore, not all method calls use the -> operator. For example,

    new Foo

    Forms of method calls:

    $class->method(LIST) # Static method call. $object->method(LIST) # Instance method call. $x->Class::method(LIST) # Pretend the LHS is class "Class". $x->SUPER::method(LIST) # Pretend the LHS is its super class. method $x LIST; # Indirect method syntax

    I think that's all of them.

    Horse::speak("Horse") is a sub call. Subroutines aren't inherited. Subroutines don't have classes, so subroutines don't have parent classes, so subroutines have nothing from which they could inherit.

      Thanks for the help. I think I'm getting a feel for it now.

      class::method();

      Is more like a name which is either defined or not.
      There is no @class::ISA array search for "method".
      There is no "automatic" first argument=class passed to the method.

      class->method();

      dereferences class for "method" and if not found will then use the "special method lookup mechanism" to search the classes listed in the @ISA array for "method"
      The class name is automatically passed to "method" as the 1st argument.

      -----
      Fairly close?
      Thanks again.

        There is no @class::ISA array search for "method".

        Correct, because you're not calling it as a method.

        There is no "automatic" first argument=class passed to the method.

        Correct, because you're not calling it as a method.

        class->method(); dereferences class for "method"

        Incorrect terminology, but yes. class->method() calls Class's method method, using inheritance if necessary.