sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:
Okay, my mind went blank, much too late last night (and not for bottled reasons). I coded what I intended to be a package with an inherited constructor, but the inherited routine was never called. The code looked like this: (Perl 5.10.0)
Edit: Typo in constructor-call removed.package Foo; use base qw/Bar/; sub new { my $class = shift; my $self = $class->SUPER::new(@_); bless $self, $class; return $self; } ... (in main) $bletch = Foo->new; print ref($bletch); # gives "Foo"
When I set croak calls and other things in the supposedly-inherited routine (in Foo), they never went off. But the routine in Bar did.
Furthermore: other methods defined in Foo (but not in Bar...) were available. So, it’s not like Perl didn’t know what package I was talking to ... it’s just that a routine defined in the child-class was ignored in favor of the parent, and I don’t know quite why.
Sure, I could define an initialize() method and call that from the constructor, but I want to understand what eluded my then-befuzzed brain.
Have I been this-quickly and so-utterly spoiled by Moose? :-)
Replies are listed 'Best First'. | |
---|---|
Re: Duh. What am I missing about inherited constructors?
by kcott (Archbishop) on Nov 04, 2010 at 13:51 UTC | |
Re: Duh. What am I missing about inherited constructors?
by JavaFan (Canon) on Nov 04, 2010 at 13:51 UTC | |
Re: Duh. What am I missing about inherited constructors?
by Anonymous Monk on Nov 04, 2010 at 13:47 UTC | |
Re: Duh. What am I missing about inherited constructors?
by hossman (Prior) on Nov 04, 2010 at 18:18 UTC | |
Re: Duh. What am I missing about inherited constructors?
by juster (Friar) on Nov 04, 2010 at 20:05 UTC | |
Re: Duh. What am I missing about inherited constructors?
by sundialsvc4 (Abbot) on Nov 05, 2010 at 01:07 UTC | |
Re: Duh. What am I missing about inherited constructors?
by sundialsvc4 (Abbot) on Nov 04, 2010 at 17:39 UTC | |
by JavaFan (Canon) on Nov 04, 2010 at 18:30 UTC |