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=15ecf37dfdc9f30e135ea4e71d4613727f5db8a8;hp=3c228b0c11698ecac07a48a1faf7b734417a0987;hb=791a5e6231a06114013593a16989e92f05409eb2;hpb=d99e6f32565008c417a6bf7a3335942df1f67e1b diff --git a/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm b/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm index 3c228b0..15ecf37 100644 --- a/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm +++ b/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm @@ -5,21 +5,18 @@ use Moose::Role; use namespace::autoclean; use B (); -use Carp (); -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); @@ -27,12 +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; + + 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;