Move the eval_environment wrapper to the Class trait from Constructor
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Trait / Method / Constructor.pm
index 8c36810..219e044 100644 (file)
@@ -1,26 +1,22 @@
 package MooseX::StrictConstructor::Trait::Method::Constructor;
 
-use strict;
-use warnings;
+use Moose::Role;
 
-use B ();
-use Carp ();
+use namespace::autoclean;
 
-use Moose::Role;
+use B ();
 
-around '_generate_BUILDALL' => sub {
+around _generate_BUILDALL => sub {
     my $orig = shift;
     my $self = shift;
 
     my $source = $self->$orig();
     $source .= ";\n" if $source;
 
-    my @attrs = (
-        '__INSTANCE__ => 1,',
-        map { B::perlstring($_) . ' => 1,' }
-        grep {defined}
-        map  { $_->init_arg() } @{ $self->_attributes() }
-    );
+    my @attrs = '__INSTANCE__ => 1,';
+    push @attrs, map { B::perlstring($_) . ' => 1,' }
+        grep { defined }
+        map  { $_->init_arg() } @{ $self->_attributes() };
 
     $source .= <<"EOF";
 my \%attrs = (@attrs);
@@ -28,14 +24,12 @@ my \%attrs = (@attrs);
 my \@bad = sort grep { ! \$attrs{\$_} }  keys \%{ \$params };
 
 if (\@bad) {
-    Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad";
+    Moose->throw_error("Found unknown attribute(s) passed to the constructor: \@bad");
 }
 EOF
 
     return $source;
-};
-
-no Moose::Role;
+} if $Moose::VERSION < 1.9900;
 
 1;