When inlining with Moose 2.0+, close over hash of allowed attrs rather than regenerat...
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Trait / Method / Constructor.pm
index 0ceec12..ae5d3fb 100644 (file)
@@ -31,7 +31,25 @@ if (\@bad) {
 EOF
 
     return $source;
-};
+} if $Moose::VERSION < 1.9900;
+
+around _eval_environment => sub {
+    my $orig = shift;
+    my $self = shift;
+
+    my $env = $self->$orig();
+
+    my %attrs = map { $_ => 1 }
+        grep { defined }
+        map  { $_->init_arg() }
+        $self->associated_metaclass()->get_all_attributes();
+
+    $attrs{__INSTANCE__} = 1;
+
+    $env->{'%allowed_attrs'} = \%attrs;
+
+    return $env;
+} if $Moose::VERSION >= 1.9900;
 
 1;