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 {
my $orig = shift;
map { $_->init_arg() } @{ $self->_attributes() }
);
- $source .= <<"EOF";
-my \%attrs = (@attrs);
-
-my \@bad = sort grep { ! \$attrs{\$_} } keys \%{ \$params };
+ my $MY = 'my';
+ if ($] >= 5.009004) {
+ $source .= "use feature 'state';\n";
+ $MY = 'state';
+ }
-if (\@bad) {
- Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad";
+ $source .= <<"EOF";
+$MY \$attrs = { @attrs };
+if (my \@bad = sort grep { ! \$attrs->{\$_} } keys %\$params) {
+ Moose->throw_error("Found unknown attribute(s) passed to the constructor: \@bad");
}
EOF
return $source;
};
-no Moose::Role;
-
1;
# ABSTRACT: A role to make immutable constructors strict