in reply to Is there a way to know why the DESTROY method was invoked?

Yes.

#! perl -slw use strict; use Carp qw[ cluck ]; my $x = 0; $SIG{ __DIE__ } = sub{ $x = 1 }; sub DESTROY{ cluck 'DESTROY called' . ($x ? ' after die':'') } { my $r=bless[]; } my $r = bless[]; die 'dying'; __END__ c:\test>junk79 DESTROY called at C:\test\junk79.pl line 9 main::DESTROY('main=ARRAY(0xacf98)') called at C:\test\junk79. +pl line 15 eval {...} called at C:\test\junk79.pl line 15 dying at C:\test\junk79.pl line 17. DESTROY called after die at C:\test\junk79.pl line 9 main::DESTROY('main=ARRAY(0x2e67e8)') called at C:\test\junk79 +.pl line 17 eval {...} called at C:\test\junk79.pl line 17

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

Replies are listed 'Best First'.
Re^2: Is there a way to know why the DESTROY method was invoked?
by erabus (Sexton) on Feb 18, 2010 at 18:49 UTC
    Thank you.