in reply to Overriding constructor
package Child; use base qw(Parent); sub new { my $class = shift; my $self = $class->SUPER::new(); # call superclass' constructor wi +th provided classname $self->do_child_specific_stuff(); return $self; }
If the superclass doesn't do the right thing with the provided class (your provided code does the right thing, but you never know..) you can force the right class after the fact:
# ... my $self = $class->SUPER::new(); bless $self,$class; # re-bless to right classname $self->do_child_specific_stuff(); # ...
|
|---|