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=e3dd07b086c80b14e5d20ff49412e286fc29914c;hpb=1a4f77329859d1a5058064cdb3eecdfa30e226b0;p=gitmo%2FMooseX-StrictConstructor.git diff --git a/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm b/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm index e3dd07b..1eceed7 100644 --- a/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm +++ b/lib/MooseX/StrictConstructor/Trait/Method/Constructor.pm @@ -1,12 +1,10 @@ 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; @@ -22,21 +20,22 @@ 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 return $source; }; -no Moose::Role; - 1; # ABSTRACT: A role to make immutable constructors strict @@ -45,16 +44,6 @@ __END__ =pod -=head1 SYNOPSIS - - Moose::Util::MetaRole::apply_metaroles( - for_class => $caller, - class => { - constructor => - ['MooseX::StrictConstructor::Trait::Method::Constructor'], - }, - ); - =head1 DESCRIPTION This role simply wraps C<_generate_BUILDALL()> (from