#!/usr/bin/perl -w use strict; use Test::More; use Test::DESTROY tests => 6; my $foo = bless {},'My::Test::Class'; destroyed_ok($foo,"Simple class"); my $foo1 = bless {},'My::Test::Class'; my $bar = $foo1; destroyed_ok($foo1,"Simple class with two references (expected fail)"); my $foo2 = bless {},'My::Test::Class'; $foo2->{child1} = bless {},'My::Test::Class'; $foo2->{child2} = bless {},'My::Test::Class'; destroyed_ok($foo2,"Simple class with two references"); my $foo3 = bless {},'My::Test::Class'; $bar = $foo3; $foo3->{child1} = bless {},'My::Test::Class'; $foo3->{child2} = bless {},'My::Test::Class'; destroyed_ok($foo3,"Simple class with two references (expected fail)"); my $foo4 = bless {},'My::Test::Class::Destructor'; my $called = 0; sub My::Test::Class::Destructor::DESTROY { $called++; }; destroyed_ok($foo4,"Simple class with two references"); is($called,1,"Previous destructor gets called");