But the secondmethod() that gets called is the over-ride version, because $self is a reference to to the child object.

Which is exactly as it should be - that's the nature of polymorphism.

This isn't anything unique to Perl. Shortly after reading the original thread, I talked to a friend who's a Java programmer. He's been writing Java more-or-less exclusively for as long as I've known him (we met in 1999) and never touched Perl in his life. When I told him about the original post and that child::tellName was called instead of person::tellName, his exact reply was, "And that surprised him?"

If you want to ignore polymorphism and have person::introduce always call person::tellName instead of any overridden version, then change the call in person::tellName from $self->tellName(); (which calls any overrides which may be in place for $self's class) to person::tellName($self); (which always calls person's version regardless of $self's class). I've already posted a revised version of the sample code which demonstrates this in the other thread at Re^4: my $self is stumped!.


In reply to Re^3: SUPER in OOPerl is dumped with $self by dsheroh
in thread SUPER in OOPerl is dumped with $self by atemon

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.