From: Jesse Luehrs Date: Fri, 19 Nov 2010 00:11:44 +0000 (-0600) Subject: update to work with new moose X-Git-Tag: v0.13~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=01265e2a46aee790b0616f8ba64df57817daafd6;p=gitmo%2FMooseX-StrictConstructor.git update to work with new moose --- diff --git a/Changes b/Changes index d4f955e..d370017 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ +- Updated to work with new Moose + 0.12 2010-10-29 - Switched tests to use Test::Fatal instead of Test::Exception. diff --git a/dist.ini b/dist.ini index 05f454a..69d4810 100644 --- a/dist.ini +++ b/dist.ini @@ -29,7 +29,7 @@ repository.type = git [CheckChangeLog] [Prereqs] -Moose = 0.94 +Moose = 1.9900 [Prereqs / TestRequires] Test::Fatal = 0 diff --git a/lib/MooseX/StrictConstructor.pm b/lib/MooseX/StrictConstructor.pm index 28c71e7..2f2367a 100644 --- a/lib/MooseX/StrictConstructor.pm +++ b/lib/MooseX/StrictConstructor.pm @@ -7,12 +7,12 @@ use Moose 0.94 (); use Moose::Exporter; use Moose::Util::MetaRole; use MooseX::StrictConstructor::Role::Object; -use MooseX::StrictConstructor::Role::Meta::Method::Constructor; +use MooseX::StrictConstructor::Role::Meta::Class; Moose::Exporter->setup_import_methods( class_metaroles => { - constructor => - ['MooseX::StrictConstructor::Role::Meta::Method::Constructor'] + class => + ['MooseX::StrictConstructor::Role::Meta::Class'] }, base_class_roles => ['MooseX::StrictConstructor::Role::Object'], ); diff --git a/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm b/lib/MooseX/StrictConstructor/Role/Meta/Class.pm similarity index 51% rename from lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm rename to lib/MooseX/StrictConstructor/Role/Meta/Class.pm index 43b2aa2..7a034e8 100644 --- a/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm +++ b/lib/MooseX/StrictConstructor/Role/Meta/Class.pm @@ -1,4 +1,4 @@ -package MooseX::StrictConstructor::Role::Meta::Method::Constructor; +package MooseX::StrictConstructor::Role::Meta::Class; use strict; use warnings; @@ -8,31 +8,27 @@ use Carp (); use Moose::Role; -around '_generate_BUILDALL' => sub { +around '_inline_BUILDALL' => sub { my $orig = shift; my $self = shift; - my $source = $self->$orig(); - $source .= ";\n" if $source; + my @source = $self->$orig(); my @attrs = ( '__INSTANCE__ => 1,', map { B::perlstring($_) . ' => 1,' } grep {defined} - map { $_->init_arg() } @{ $self->_attributes() } + map { $_->init_arg() } $self->get_all_attributes() ); - $source .= <<"EOF"; -my \%attrs = (@attrs); - -my \@bad = sort grep { ! \$attrs{\$_} } keys \%{ \$params }; - -if (\@bad) { - Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad"; -} -EOF - - return $source; + return ( + @source, + 'my %attrs = (' . join(' ', @attrs) . ');', + 'my @bad = sort grep { !$attrs{$_} } keys %{ $params };', + 'if (@bad) {', + 'Carp::confess "Found unknown attribute(s) passed to the constructor: @bad";', + '}', + ); }; no Moose::Role; @@ -57,9 +53,8 @@ __END__ =head1 DESCRIPTION -This role simply wraps C<_generate_BUILDALL()> (from -C) so that immutable classes have a +This role simply wraps C<_inline_BUILDALL()> (from +C) so that immutable classes have a strict constructor. =cut -