in reply to OO & multiple inheritance.

Method calls in Perl are what is called "virtual" in other languages. If an object is blessed to Dog, and you call $obj->speak(), Perl searches @INC starting from Dog's.

Your constructor is already subclassable -- that's what your blessing to $class achieves -- so instead of calling Animal->new call Dog->new and Cat->new directly, and don't bother with the type; it'll happen automagically.

(You can tell what kind of Animal you have by calling ref $obj on an instance.)

Replies are listed 'Best First'.
•Re^2: OO & multiple inheritance.
by merlyn (Sage) on Nov 18, 2004 at 14:34 UTC
    (You can tell what kind of Animal you have by calling ref $obj on an instance.)
    But don't do that, as it will break the "null subclass test". Instead, use "isa" or "can" to test inheritance or capability. The code:
    if (ref $this eq "Some::Class::Of::Interest") { ... }
    is almost always wrong, and is red-flagged in my code reviews.

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

      Quick thought for Perl6: ref() could return an any() junction created with the @ISA for the class. Then ref() and isa() would be functionally equivilent.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      Yes, you are right, of course.