in reply to Supra Class for Inheritance?

You get that behaviour by default.

{ package Parent; sub new { my ($class) = @_; return bless({}, $class); } sub finalise { my ($self) = @_; $self->finalise_body(); } sub finalise_body { my ($self) = @_; print(__PACKAGE__, "\n"); } } { package ChildWith; our @ISA = 'Parent'; sub finalise_body { my ($self) = @_; print(__PACKAGE__, "\n"); } } { package ChildWithout; our @ISA = 'Parent'; } { ChildWith ->new->finalise(); # ChildWith ChildWithout->new->finalise(); # Parent }

In C++ term, methods of this type are called virtual methods.

Replies are listed 'Best First'.
Re^2: Supra Class for Inheritance?
by tbutler (Initiate) on Aug 21, 2010 at 02:51 UTC
    Thanks -- I was just totally overlooking the obvious solution. Even though I had made everything else OOP, I was calling finalize_body as just a straight subroutine. Doing $self->finalize_body does the trick. Thank you! Hard to believe that drove me crazy for so long. Sheesh!