Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found