> Thanks, but I need something that destroys in reverse order, i.e.
> child-first.

Hello Keary,

I read up a bit in (the most brilliant) OO Perl book

You could
1) call the base class' destructor yourself
package subsubclass;
sub DESTROY {
  my $self = shift;
  $self->subclass::DESTROY();
  $self->class::DESTROY();
}

2) generalize 1)
package subsubclass;
sub DESTROY {
  my $self = shift;
  foreach my $parent ( @ISA ) {
    my $destructor = $parent->can("DESTROY");
    $self->$destructor() if $destructor;
  }
}

3) rebless, works only if you don't have multiple inheritance
package subsubclass;
sub DESTROY {
  my $self = shift;
  bless $self, $ISA[0];
}
package subclass;
....
  bless $self, $ISA[0];


HTH,
Axel

Reply via email to