From: gfx Date: Sat, 10 Oct 2009 08:57:45 +0000 (+0900) Subject: Add localization of $@ and $? in DESTROY X-Git-Tag: 0.37_06~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7746ba36780a891bd98d610a99e42ccae5e8cdb2;p=gitmo%2FMouse.git Add localization of $@ and $? in DESTROY --- diff --git a/lib/Mouse/Meta/Method/Destructor.pm b/lib/Mouse/Meta/Method/Destructor.pm index 66f4709..28e260f 100644 --- a/lib/Mouse/Meta/Method/Destructor.pm +++ b/lib/Mouse/Meta/Method/Destructor.pm @@ -21,7 +21,17 @@ sub _generate_destructor{ my $source = sprintf("#line %d %s\n", __LINE__, __FILE__) . <<"..."; sub { my \$self = shift; - $demolishall; + local \$?; + + my \$e = do{ + local \$@; + eval{ + $demolishall; + }; + \$@; + }; + no warnings 'misc'; + die \$e if \$e; # rethrow } ... diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index 127a575..60f6aad 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -30,7 +30,18 @@ sub BUILDARGS { sub DESTROY { my $self = shift; - $self->DEMOLISHALL(); + local $?; + + my $e = do{ + local $@; + eval{ + $self->DEMOLISHALL(); + }; + $@; + }; + + no warnings 'misc'; + die $e if $e; # rethrow } sub BUILDALL {