Add localization of $@ and $? in DESTROY
[gitmo/Mouse.git] / lib / Mouse / Object.pm
index 127a575..60f6aad 100644 (file)
@@ -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 {