This ended up calling back to my overridden funcB() method as the hash passed in is blessed into my class.

Yes. Yes it does. That's the way polymorphism works and is nothing specific to Perl.

package Dog; sub pull_tail { $self->speak; } sub speak { print "Woof!\n"; } package AngryDog; sub speak { print "Grrrrr...\n"; }
What would you expect to happen when you pull an AngryDog's tail? That it would bark (because pull_tail is defined by the base Dog class) or that it would growl (because that's what AngryDogs say)? It's an AngryDog, so it should respond accordingly.

(If you wanted all Dogs to react like a base Dog instead of according to their subclass, you could force them to always use the base Dog::speak by changing the $self->speak line to Dog::speak($self), but that's done very rarely, as there are very few cases where it's what you actually want.)


In reply to Re: Overriding methods and Inheritance by dsheroh
in thread Overriding methods and Inheritance by bamaindk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.