X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStrictConstructor%2FTrait%2FMethod%2FConstructor.pm;h=1eceed7256bcf5ffbed76cec82cedd53035632af;hb=refs%2Fheads%2Fchip%2Ffast1;hp=3c228b0c11698ecac07a48a1faf7b734417a0987;hpb=d99e6f32565008c417a6bf7a3335942df1f67e1b;p=gitmo%2FMooseX-StrictConstructor.git diff --git a/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm b/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm index 3c228b0..1eceed7 100644 --- a/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm +++ b/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm @@ -5,7 +5,6 @@ use Moose::Role; use namespace::autoclean; use B (); -use Carp (); around '_generate_BUILDALL' => sub { my $orig = shift; @@ -21,13 +20,16 @@ around '_generate_BUILDALL' => sub { 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