nomis80 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
This must be a trivial question but I couldn't find any answer for it in the archives or by using Google. Here goes...
I want to inherit from a class, and I want my child class' constructor to add some behavior to the parent's. I didn't code the parent class and am not in a position to modify it, which means I can't do the _init() trick.
package Parent; sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = {}; bless $self, $class; return $self; } package Child; use base qw(Parent); sub new { # what goes here? $self->do_child_specific_stuff(); return $self; }
What code should go into Child::new()? Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Overriding constructor
by Joost (Canon) on Aug 12, 2005 at 15:07 UTC | |
|
Re: Overriding constructor
by phaylon (Curate) on Aug 12, 2005 at 14:55 UTC | |
by nomis80 (Sexton) on Aug 12, 2005 at 15:00 UTC | |
by chromatic (Archbishop) on Aug 12, 2005 at 17:09 UTC | |
by phaylon (Curate) on Aug 12, 2005 at 15:46 UTC | |
|
Re: Overriding constructor
by merlyn (Sage) on Aug 12, 2005 at 15:38 UTC | |
by xdg (Monsignor) on Aug 12, 2005 at 15:59 UTC | |
|
Re: Overriding constructor
by Codon (Friar) on Aug 12, 2005 at 15:31 UTC |