Make sure we always local-ize $@ and $SIG{__DIE__} for code evals.
[gitmo/Class-MOP.git] / lib / Class / MOP / Method / Generated.pm
index 5af96b8..ea0ea2c 100644 (file)
@@ -29,22 +29,29 @@ sub _initialize_body {
 sub _eval_closure {
     # my ($self, $captures, $sub_body) = @_;
     my $__captures = $_[1];
-    eval join(
-        "\n",
-        (
+
+    my $code;
+
+    my $e = do {
+        local $@;
+        local $SIG{__DIE__};
+        $code = eval join
+            "\n", (
             map {
                 /^([\@\%\$])/
                     or die "capture key should start with \@, \% or \$: $_";
-                q[my ]
-                . $_ . q[ = ]
-                . $1
-                . q[{$__captures->{']
-                . $_
-                . q['}};];
-            } keys %$__captures
-        ),
-        $_[2]
-    );
+                q[my ] 
+                    . $_ . q[ = ] 
+                    . $1
+                    . q[{$__captures->{']
+                    . $_ . q['}};];
+                } keys %$__captures
+            ),
+            $_[2];
+        $@;
+    };
+
+    return ( $code, $e );
 }
 
 sub _add_line_directive {