From: Dave Rolsky Date: Fri, 11 Sep 2009 16:26:13 +0000 (-0500) Subject: Localize all status vars in DEMOLISH X-Git-Tag: 0.90~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c989424b69da5d9960fe3d568bf574d942343b48;p=gitmo%2FMoose.git Localize all status vars in DEMOLISH --- diff --git a/Changes b/Changes index db05323..060539a 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,11 @@ Next methods. This has been removed. You must be explicit in your handles declaration for all Native Traits. (Dave Rolsky) + * Moose::Object + - DEMOLISH now localizes all of Perl's global status variables (worst + Perl feature evah?). Based on a patch from zefream. RT #48271. (doy + and Dave Rolsky) + 0.89_02 Thu, Sep 10, 2009 * Moose::Meta::Attribute::Native - Fix Hash, which still had 'empty' instead of 'is_empty'. (hdp) diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 7cb1e73..fefdfe3 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -86,17 +86,9 @@ sub DEMOLISHALL { } sub DESTROY { - # if we have an exception here ... - if ($@) { - # localize the $@ ... - local $@; - # run DEMOLISHALL ourselves, ... - $_[0]->DEMOLISHALL(in_global_destruction); - # and return ... - return; - } - # otherwise it is normal destruction + local ( $., $@, $!, $^E, $? ); $_[0]->DEMOLISHALL(in_global_destruction); + return; } # support for UNIVERSAL::DOES ... diff --git a/t/100_bugs/012_DEMOLISH_eats_mini.t b/t/100_bugs/012_DEMOLISH_eats_mini.t index beb51ab..cb390bc 100644 --- a/t/100_bugs/012_DEMOLISH_eats_mini.t +++ b/t/100_bugs/012_DEMOLISH_eats_mini.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 7; use Test::Exception; @@ -45,3 +45,29 @@ use Test::Exception; like( $@, qr/Bar died/, "... Bar plain" ); is( $obj, undef, "... the object is undef" ); } + +{ + package Baz; + use Moose; + + sub DEMOLISH { + $@ = 1; + $? = 0; + $! = 0; + } +} + +{ + local $@ = 0; + local $? = 42; + local $! = 84; + + { + Baz->new; + } + + is( $@, 0, '$@ is still 0 after object is demolished' ); + is( $?, 42, '$? is still 42 after object is demolished' ); + is( $! + 0, 84, '$! is still 84 after object is demolished' ); +} +