Remove extra newline
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Trait / Method / Constructor.pm
index e3dd07b..15ecf37 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,30 @@ 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;
-};
+} if $Moose::VERSION < 1.9900;
+
+around _eval_environment => sub {
+    my $orig = shift;
+    my $self = shift;
 
-no Moose::Role;
+    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;
 
@@ -45,16 +57,6 @@ __END__
 
 =pod
 
-=head1 SYNOPSIS
-
-  Moose::Util::MetaRole::apply_metaroles(
-      for_class => $caller,
-      class     => {
-          constructor =>
-              ['MooseX::StrictConstructor::Trait::Method::Constructor'],
-      },
-  );
-
 =head1 DESCRIPTION
 
 This role simply wraps C<_generate_BUILDALL()> (from