use Moose::Exporter;
use Moose::Util::MetaRole;
-{
- my %class_meta = ( class => ['MooseX::StrictConstructor::Trait::Class'] );
-
- if ( $Moose::VERSION < 1.9900 ) {
- require MooseX::StrictConstructor::Trait::Method::Constructor;
- $class_meta{constructor}
- = ['MooseX::StrictConstructor::Trait::Method::Constructor'];
- }
-
- Moose::Exporter->setup_import_methods(
- class_metaroles => \%class_meta,
- );
-}
+use MooseX::StrictConstructor::Trait::Class;
+use MooseX::StrictConstructor::Trait::Method::Constructor;;
+
+Moose::Exporter->setup_import_methods(
+ class_metaroles => {
+ class => ['MooseX::StrictConstructor::Trait::Class'],
+ constructor =>
+ ['MooseX::StrictConstructor::Trait::Method::Constructor'],
+ },
+);
1;
return (
@source,
- 'my %attrs = (' . ( join ' ', @attrs ) . ');',
- 'my @bad = sort grep { !$attrs{$_} } keys %{ $params };',
+ 'my @bad = sort grep { !$allowed_attrs{$_} } keys %{ $params };',
'if (@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;
+
+ 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;