factor codegen stuff out to Eval::Closure
[gitmo/Class-MOP.git] / lib / Class / MOP / Method / Constructor.pm
index d614587..05c8d92 100644 (file)
@@ -6,6 +6,7 @@ use warnings;
 
 use Carp         'confess';
 use Scalar::Util 'blessed', 'weaken';
+use Try::Tiny;
 
 our $VERSION   = '1.11';
 $VERSION = eval $VERSION;
@@ -121,11 +122,15 @@ sub _generate_constructor_method_inline {
     $source .= ";\n" . '}';
     warn $source if $self->options->{debug};
 
-    my ( $code, $e ) = $self->_eval_closure(
-        $close_over,
-        $source
-    );
-    confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e" if $e;
+    my $code = try {
+        $self->_compile_code(
+            source => $source,
+            environment => $close_over,
+        );
+    }
+    catch {
+        confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$_";
+    };
 
     return $code;
 }