lifang11 has asked for the wisdom of the Perl Monks concerning the following question:
====================================== B.pm#!/usr/bin/perl package A; use warnings; use strict; sub new { my $object = shift; my $class = ref($object)||$object; my $self = {}; bless($self,$class); return $self; } sub DESTROY { print("DESTROY in A","\n"); } sub hello { print("hello in A\n"); } return 1;
============================== main.pl#!/usr/bin/perl package B; use warnings; use strict; use A; our @ISA=qw(A); sub new { my $object = shift; my $class = ref($object)||$object; my $self = $class->SUPER::new(); bless($self,$class); return $self; } sub DESTROY { print("DESTROY in B","\n"); } sub hello { my $self = shift; $self->SUPER::hello(); print("hello in B\n"); } return 1;
===================================== output:#!/usr/bin/perl use warnings; use strict; use FindBin; use lib "$FindBin::Bin/class"; use B; my $b = new B(); $b->hello();
Why is the base class's destructor not called?hello in A hello in B DESTROY in B
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why is the base class's destructor not called?
by BrowserUk (Patriarch) on Jan 21, 2014 at 06:42 UTC | |
by lifang11 (Novice) on Jan 22, 2014 at 11:27 UTC | |
by choroba (Cardinal) on Jan 22, 2014 at 11:31 UTC | |
by Athanasius (Archbishop) on Jan 22, 2014 at 13:17 UTC | |
by BrowserUk (Patriarch) on Jan 22, 2014 at 18:43 UTC | |
by ikegami (Patriarch) on Jan 24, 2014 at 14:55 UTC | |
|
Re: Why is the base class's destructor not called?
by tobyink (Canon) on Jan 21, 2014 at 10:14 UTC |