Syndaryl has asked for the wisdom of the Perl Monks concerning the following question:
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:Works a treat. However if I have something likesub 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; }
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Extending parent object method?
by chromatic (Archbishop) on Mar 09, 2012 at 20:40 UTC | |
by Syndaryl (Initiate) on Mar 12, 2012 at 13:51 UTC | |
by chromatic (Archbishop) on Mar 12, 2012 at 15:24 UTC |