Answered! Many thanks again!


No Moose, just bare perl... More's the pity.

I have a child object inheriting a parent object - I can call methods that are on the parent object, not the child, access properties defined on the parent object, etc.

I can override a parent method, but in this case I don't want to do that - I want to call the parent object's method and then execute more child-specific code after that. I have the code to call the parent object's constructor from within my childs constructor, but the same code doesn't seem to work on other methods, which is both annoying and confusing me.

What I have for my constructor:
sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(@_); bless $self, $class; # do other stuff here for the child object... return $self; }
Works a treat. However if I have something like
sub reset { my $self = shift; my $class = ref($self) || $self; $class->SUPER::reset(@_); $self->setMatchMethod(\&multiline_match); return $self; }

perl barfs up and reports "Can't use string (<object name>) as a HASH ref while "strict refs" in use at ..." on the $class->SUPER::reset(@_) line.

It's even truncating the object name, which is REALLY confusing me - instead of "...::DocumentManager::PlainText" for the string it's unhappy with, it's saying "...::DocumentManager::Pl". (full object path redacted for the sake of my employer).

In a fit of wild flailing I tried $class::SUPER::reset($self, @_); but that just gives a syntax error.

So I'm clearly Not Doing This Right.


In reply to Extending parent object method? by Syndaryl

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.