Make sure to local-ize $@ and $SIG{__DIE__} for each eval, and rethrow
[gitmo/Class-MOP.git] / lib / Class / MOP / Module.pm
index ffd6721..6d0f785 100644 (file)
@@ -50,8 +50,13 @@ sub _instantiate_module {
     $code .= "\$$package_name\:\:AUTHORITY = '" . $authority . "';"
         if defined $authority;
 
-    eval $code;
-    confess "creation of $package_name failed : $@" if $@;
+    my $e = do {
+        local $@;
+        local $SIG{__DIE__};
+        eval $code;
+        $@;
+    };
+    confess "creation of $package_name failed : $e" if $e;
 }
 
 1;