X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-StrictConstructor.git;a=blobdiff_plain;f=lib%2FMooseX%2FStrictConstructor%2FTrait%2FMethod%2FConstructor.pm;h=8d8590f1b20d667af8151b9a1f9a07281e4a6636;hp=8c368105255fb0ef3b0aa0d287d0d597690b4610;hb=0b60c40bd27a81249ffaae24e6cb8b6423364bcf;hpb=ce8f6d73680c9395b9bc5add89f3c6e3be2bc1be diff --git a/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm b/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm index 8c36810..8d8590f 100644 --- a/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm +++ b/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm @@ -1,26 +1,23 @@ 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 +25,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; + + 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; -no Moose::Role; + return $env; +} if $Moose::VERSION >= 1.9900; 1;