From: Dave Rolsky Date: Sun, 26 Sep 2010 19:12:22 +0000 (-0500) Subject: Refactored native trait accessors so they are done entirely in roles. X-Git-Tag: 1.15~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b9641b857cdd065a68f9b74ad072b1d58fcd4e1;p=gitmo%2FMoose.git Refactored native trait accessors so they are done entirely in roles. The class to do the inlining is generated based on the attribute's accessor & delegation metaclasses, which means this works even when the attribute changes those classes. Added code to check if the attr's slot access can be inlined, and to use a slower but working code path if it can't (see MX::AttributeTree for an example of why this might be needed). --- diff --git a/lib/Moose/Meta/Attribute/Native/Trait.pm b/lib/Moose/Meta/Attribute/Native/Trait.pm index ee44d6d..1dcf13c 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait.pm @@ -86,12 +86,13 @@ around '_make_delegation_method' => sub { unless $accessor_class && $accessor_class->can('new'); return $accessor_class->new( - name => $handle_name, - package_name => $self->associated_class->name, - attribute => $self, - is_inline => 1, - curried_arguments => \@curried_args, - root_types => [ $self->_root_types ], + name => $handle_name, + package_name => $self->associated_class->name, + delegate_to_method => $name, + attribute => $self, + is_inline => 1, + curried_arguments => \@curried_args, + root_types => [ $self->_root_types ], ); }; @@ -102,7 +103,17 @@ sub _root_types { sub _native_accessor_class_for { my ( $self, $suffix ) = @_; - return 'Moose::Meta::Method::Accessor::Native::' . $self->_native_type . '::' . $suffix; + my $role + = 'Moose::Meta::Method::Accessor::Native::' + . $self->_native_type . '::' + . $suffix; + + return Moose::Meta::Class->create_anon_class( + superclasses => + [ $self->accessor_metaclass, $self->delegation_metaclass ], + roles => [$role], + cache => 1, + )->name; } sub _build_native_type { diff --git a/lib/Moose/Meta/Method/Accessor/Native.pm b/lib/Moose/Meta/Method/Accessor/Native.pm index 62cde0f..cb1f38b 100644 --- a/lib/Moose/Meta/Method/Accessor/Native.pm +++ b/lib/Moose/Meta/Method/Accessor/Native.pm @@ -10,26 +10,13 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor', 'Moose::Meta::Method::Delegation'; +use Moose::Role; -sub new { +around new => sub { + my $orig = shift; my $class = shift; my %options = @_; - die "Cannot instantiate a $class object directly" - if $class eq __PACKAGE__; - - ( exists $options{attribute} ) - || confess "You must supply an attribute to construct with"; - - ( blessed( $options{attribute} ) - && $options{attribute}->isa('Class::MOP::Attribute') ) - || confess - "You must supply an attribute which is a 'Class::MOP::Attribute' instance"; - - ( $options{package_name} && $options{name} ) - || confess "You must supply the package_name and name parameters"; - exists $options{curried_arguments} || ( $options{curried_arguments} = [] ); @@ -38,25 +25,20 @@ sub new { || confess 'You must supply a curried_arguments which is an ARRAY reference'; - $options{delegate_to_method} = lc( ( split /::/, $class)[-1] ); - $options{definition_context} = $options{attribute}->definition_context; - my $self = $class->_new( \%options ); + $options{accessor_type} = 'native'; - weaken( $self->{'attribute'} ); + return $class->$orig(%options); +}; - $self->_initialize_body; - - return $self; -} - -sub _new { +around _new => sub { + shift; my $class = shift; my $options = @_ == 1 ? $_[0] : {@_}; return bless $options, $class; -} +}; sub root_types { (shift)->{'root_types'} } @@ -115,28 +97,26 @@ sub _inline_check_argument_count { sub _minimum_arguments { 0 } sub _maximum_arguments { undef } -sub _inline_check_arguments { q{} } - -sub _inline_get { +override _inline_get => sub { my ( $self, $instance ) = @_; return $self->_slot_access_can_be_inlined - ? $self->SUPER::_inline_get($instance) + ? super() : "${instance}->\$reader"; -} +}; -sub _inline_store { +override _inline_store => sub { my ( $self, $instance, $value ) = @_; return $self->_slot_access_can_be_inlined - ? $self->SUPER::_inline_store( $instance, $value ) + ? super() : "${instance}->\$writer($value)"; -} +}; -sub _eval_environment { +override _eval_environment => sub { my $self = shift; - my $env = $self->SUPER::_eval_environment(@_); + my $env = super(); $env->{'@curried'} = $self->curried_arguments; @@ -153,7 +133,7 @@ sub _eval_environment { $env->{'$writer'} = \$writer; return $env; -} +}; sub _slot_access_can_be_inlined { my $self = shift; @@ -161,4 +141,6 @@ sub _slot_access_can_be_inlined { return $self->is_inline && $self->_instance_is_inlinable; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array.pm b/lib/Moose/Meta/Method/Accessor/Native/Array.pm index 4cde45b..97162a0 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array.pm @@ -3,6 +3,8 @@ package Moose::Meta::Method::Accessor::Native::Array; use strict; use warnings; +use Moose::Role; + use Scalar::Util qw( looks_like_number ); our $VERSION = '1.14'; @@ -18,4 +20,6 @@ sub _inline_check_var_is_valid_index { . qq{ unless defined $var && $var =~ /^-?\\d+\$/;}; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/Writer.pm index 22ba0fe..7b22630 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/Writer.pm @@ -3,20 +3,15 @@ package Moose::Meta::Method::Accessor::Native::Array::Writer; use strict; use warnings; -use Class::MOP::MiniTrait; - our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; -Class::MOP::MiniTrait::apply( __PACKAGE__, - 'Moose::Meta::Method::Accessor::Native::Array' -); -Class::MOP::MiniTrait::apply( __PACKAGE__, - 'Moose::Meta::Method::Accessor::Native::Collection' -); +with 'Moose::Meta::Method::Accessor::Native::Writer', + 'Moose::Meta::Method::Accessor::Native::Array', + 'Moose::Meta::Method::Accessor::Native::Collection'; sub _new_members {'@_'} diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm index 2c3f168..fce1964 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm @@ -7,10 +7,27 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base qw( - Moose::Meta::Method::Accessor::Native::Array::set - Moose::Meta::Method::Accessor::Native::Array::get -); +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::set' => { + -excludes => [ + qw( _generate_method + _minimum_arguments + _maximum_arguments + _inline_process_arguments + _inline_check_arguments + _return_value) + ] + }, + 'Moose::Meta::Method::Accessor::Native::Array::get' => { + -excludes => [ + qw( + _generate_method + _minimum_arguments + _maximum_arguments + ) + ] + }; sub _generate_method { my $self = shift; @@ -58,8 +75,6 @@ sub _generate_method { sub _minimum_arguments {2} sub _maximum_arguments {2} -sub _adds_members {1} - -sub _new_members {'$_[1]'} +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/clear.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/clear.pm index 1f65ae2..1257b41 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/clear.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/clear.pm @@ -7,7 +7,16 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _maximum_arguments { 0 } @@ -21,4 +30,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = []"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/count.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/count.pm index 331f6ff..4cb0235 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/count.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/count.pm @@ -7,7 +7,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -17,4 +20,6 @@ sub _return_value { return "scalar \@{ $slot_access }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/delete.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/delete.pm index 2577ab7..3e9e54c 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/delete.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/delete.pm @@ -7,7 +7,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + _inline_optimized_set_new_value + ) + ], +}; sub _minimum_arguments { 1 } @@ -34,4 +45,6 @@ sub _inline_optimized_set_new_value { return "splice \@{ $slot_access }, \$_[0], 1"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/elements.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/elements.pm index f8f35e5..510ac9a 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/elements.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/elements.pm @@ -7,7 +7,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -18,4 +21,6 @@ sub _return_value { return "\@{ $slot_access }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/first.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/first.pm index 83f3e3d..7323bb7 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/first.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/first.pm @@ -9,7 +9,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _minimum_arguments { 1 } @@ -30,4 +40,6 @@ sub _return_value { return "&List::Util::first( \$_[0], \@{ ${slot_access} } )"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/get.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/get.pm index e5a7d73..6da6653 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/get.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/get.pm @@ -9,11 +9,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; - -Class::MOP::MiniTrait::apply( __PACKAGE__, - 'Moose::Meta::Method::Accessor::Native::Array' -); +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ], + }, + 'Moose::Meta::Method::Accessor::Native::Array'; sub _minimum_arguments { 1 } diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/grep.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/grep.pm index 7c0b6cd..e6ac60d 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/grep.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/grep.pm @@ -7,7 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _minimum_arguments { 1 } @@ -28,4 +38,6 @@ sub _return_value { return "grep { \$_[0]->() } \@{ $slot_access }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/insert.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/insert.pm index 19674ac..8af0737 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/insert.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/insert.pm @@ -7,7 +7,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _new_members + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments { 2 } @@ -30,4 +41,6 @@ sub _inline_optimized_set_new_value { return "splice \@{ $slot_access }, \$_[0], 0, \$_[1];"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/is_empty.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/is_empty.pm index df71c8c..0ec8d8c 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/is_empty.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/is_empty.pm @@ -7,7 +7,12 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; + +sub _maximum_arguments { 0 } sub _return_value { my $self = shift; @@ -16,4 +21,6 @@ sub _return_value { return "\@{ $slot_access } ? 0 : 1"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/join.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/join.pm index feea365..bbaad84 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/join.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/join.pm @@ -7,7 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _minimum_arguments { 1 } @@ -28,4 +38,6 @@ sub _return_value { return "join \$_[0], \@{ $slot_access }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/map.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/map.pm index 6f93ae6..3013fe0 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/map.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/map.pm @@ -7,7 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _minimum_arguments { 1 } @@ -28,4 +38,6 @@ sub _return_value { return "map { \$_[0]->() } \@{ $slot_access }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/natatime.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/natatime.pm index 9b6f8a2..b905564 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/natatime.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/natatime.pm @@ -9,7 +9,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + _inline_return_value + ) + ] +}; sub _minimum_arguments {1} @@ -39,4 +50,9 @@ sub _inline_return_value { . 'return $iter;' . "\n" . '}'; } +# Not called, but needed to satisfy the Reader role +sub _return_value { } + +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/pop.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/pop.pm index f185152..ddd4fcf 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/pop.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/pop.pm @@ -7,7 +7,16 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => { + -excludes => [ + qw( _maximum_arguments + _inline_capture_return_value + _inline_optimized_set_new_value + _return_value ) + ] +}; sub _maximum_arguments { 0 } @@ -37,4 +46,6 @@ sub _return_value { return 'return $old;'; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/push.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/push.pm index 6eadc37..32ccbe1 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/push.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/push.pm @@ -7,7 +7,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => + { -excludes => ['_inline_optimized_set_new_value'] }; sub _adds_members { 1 } @@ -23,4 +26,6 @@ sub _inline_optimized_set_new_value { return "push \@{ $slot_access }, \@_"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/reduce.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/reduce.pm index 8178397..8b5e72a 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/reduce.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/reduce.pm @@ -9,7 +9,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _minimum_arguments { 1 } @@ -30,4 +40,6 @@ sub _return_value { return "List::Util::reduce { \$_[0]->( \$a, \$b ) } \@{ ${slot_access} }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/set.pm index d2b2d5a..c49e2d0 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/set.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/set.pm @@ -7,7 +7,19 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + _new_members + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments { 2 } @@ -36,4 +48,6 @@ sub _inline_optimized_set_new_value { return "${slot_access}->[ \$_[0] ] = \$_[1]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/shift.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/shift.pm index 2c40374..868f9a0 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/shift.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/shift.pm @@ -7,7 +7,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_capture_return_value + _inline_optimized_set_new_value + _return_value + ) + ] +}; sub _maximum_arguments { 0 } @@ -37,4 +48,6 @@ sub _return_value { return 'return $old'; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/shuffle.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/shuffle.pm index 6671660..87093a1 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/shuffle.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/shuffle.pm @@ -9,7 +9,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -20,4 +23,6 @@ sub _return_value { return "List::Util::shuffle \@{ $slot_access }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/sort.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/sort.pm index e7bf782..57da995 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/sort.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/sort.pm @@ -7,7 +7,16 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _maximum_arguments { 1 } @@ -27,4 +36,6 @@ sub _return_value { "\$_[0] ? sort { \$_[0]->( \$a, \$b ) } \@{ ${slot_access} } : sort \@{ $slot_access }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/sort_in_place.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/sort_in_place.pm index cdaade4..41a895f 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/sort_in_place.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/sort_in_place.pm @@ -7,7 +7,16 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _maximum_arguments { 1 } @@ -28,4 +37,6 @@ sub _potential_value { "[ \$_[0] ? sort { \$_[0]->( \$a, \$b ) } \@{ $slot_access } : sort \@{ $slot_access} ]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/splice.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/splice.pm index 78e5834..9108c89 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/splice.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/splice.pm @@ -7,7 +7,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _inline_process_arguments + _inline_check_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments { 1 } @@ -39,4 +50,6 @@ sub _inline_optimized_set_new_value { return "defined \$len ? ( splice \@{ $slot_access }, \$idx, \$len, \@_ ) : ( splice \@{ $slot_access }, \$idx )"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/uniq.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/uniq.pm index 1e357a7..9f52e4f 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/uniq.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/uniq.pm @@ -9,7 +9,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -20,4 +23,6 @@ sub _return_value { return "List::MoreUtils::uniq \@{ $slot_access }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/unshift.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/unshift.pm index b2c94cb..9cf5e60 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/unshift.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/unshift.pm @@ -7,7 +7,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Array::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => + { -excludes => ['_inline_optimized_set_new_value'] }; sub _adds_members { 1 } @@ -23,4 +26,6 @@ sub _inline_optimized_set_new_value { return "unshift \@{ $slot_access }, \@_"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/not.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/not.pm index bd47084..9cd0646 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Bool/not.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/not.pm @@ -7,9 +7,11 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _return_value { diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/set.pm index 2814f54..2686eda 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Bool/set.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/set.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _potential_value { 1 } @@ -20,4 +28,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = 1"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/toggle.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/toggle.pm index dd8383c..3a263a6 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Bool/toggle.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/toggle.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _potential_value { @@ -24,4 +32,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = $slot_access ? 0 : 1"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Bool/unset.pm b/lib/Moose/Meta/Method/Accessor/Native/Bool/unset.pm index 3fc429d..c5c45fe 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Bool/unset.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Bool/unset.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _potential_value { 0 } @@ -20,4 +28,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = 0"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Code/execute.pm b/lib/Moose/Meta/Method/Accessor/Native/Code/execute.pm index 33620ea..965cd9c 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Code/execute.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Code/execute.pm @@ -7,10 +7,9 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; -sub _minimum_arguments { 0 } -sub _maximum_arguments { undef } +with 'Moose::Meta::Method::Accessor::Native::Reader'; sub _return_value { my ( $self, $slot_access ) = @_; @@ -18,4 +17,6 @@ sub _return_value { return "${slot_access}->(\@_)"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Code/execute_method.pm b/lib/Moose/Meta/Method/Accessor/Native/Code/execute_method.pm index b833afc..5cd7ec2 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Code/execute_method.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Code/execute_method.pm @@ -7,10 +7,9 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; -sub _minimum_arguments { 0 } -sub _maximum_arguments { undef } +with 'Moose::Meta::Method::Accessor::Native::Reader'; sub _return_value { my ( $self, $slot_access ) = @_; @@ -18,4 +17,6 @@ sub _return_value { return "${slot_access}->(\$self, \@_)"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm index 45b2340..dcfa65e 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm @@ -7,15 +7,19 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -sub _value_needs_copy { +use Moose::Role; + +requires qw( _adds_members ); + +around _value_needs_copy => sub { shift; my $self = shift; return $self->_constraint_must_be_checked && !$self->_check_new_members_only; -} +}; -sub _inline_tc_code { +around _inline_tc_code => sub { shift; my ( $self, $potential_value ) = @_; @@ -30,7 +34,7 @@ sub _inline_tc_code { return $self->_inline_check_coercion($potential_value) . "\n" . $self->_inline_check_constraint($potential_value); } -} +}; sub _check_new_members_only { my $self = shift; @@ -70,16 +74,16 @@ sub _inline_check_member_constraint { ) . " for $new_value;"; } -sub _inline_check_constraint { +around _inline_check_constraint => sub { my $orig = shift; my $self = shift; return q{} unless $self->_constraint_must_be_checked; return $self->$orig( $_[0] ); -} +}; -sub _inline_get_old_value_for_trigger { +around _inline_get_old_value_for_trigger => sub { shift; my ( $self, $instance ) = @_; @@ -91,9 +95,9 @@ sub _inline_get_old_value_for_trigger { . $self->_inline_has($instance) . q{ ? } . $self->_inline_copy_old_value( $self->_inline_get($instance) ) . ": ();\n"; -} +}; -sub _eval_environment { +around _eval_environment => sub { my $orig = shift; my $self = shift; @@ -108,7 +112,7 @@ sub _eval_environment { ->_compiled_type_constraint ); return $env; -} +}; no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/Writer.pm index 628ec7b..dd7bef5 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/Writer.pm @@ -7,7 +7,9 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer'; sub _constraint_must_be_checked { my $self = shift; @@ -19,17 +21,6 @@ sub _constraint_must_be_checked { || ( $attr->should_coerce && $attr->type_constraint->has_coercion ) ); } -sub _inline_check_coercion { - my ( $self, $value ) = @_; - - my $attr = $self->associated_attribute; - - return '' - unless $attr->should_coerce && $attr->type_constraint->has_coercion; - - # We want to break the aliasing in @_ in case the coercion tries to make a - # destructive change to an array member. - return "$value = $attr->type_constraint->coerce($value);"; -} +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/dec.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/dec.pm index 85ab22f..8b84eab 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/dec.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/dec.pm @@ -7,7 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments {0} sub _maximum_arguments {1} @@ -24,4 +34,6 @@ sub _inline_optimized_set_new_value { return "$slot_access -= defined \$_[0] ? \$_[0] : 1"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/inc.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/inc.pm index 252fdb8..e25630e 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/inc.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/inc.pm @@ -7,7 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments { 0 } sub _maximum_arguments { 1 } @@ -24,4 +34,6 @@ sub _inline_optimized_set_new_value { return "$slot_access += defined \$_[0] ? \$_[0] : 1"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/reset.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/reset.pm index 9528958..14ca7ae 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/reset.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/reset.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _potential_value { @@ -24,4 +32,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = \$attr->default(\$self)"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Counter/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Counter/set.pm index 48da205..8096650 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Counter/set.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Counter/set.pm @@ -7,7 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments {1} sub _maximum_arguments {1} @@ -20,4 +30,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = \$_[0];"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash.pm index 8d5fa2c..fcb2688 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash.pm @@ -7,7 +7,7 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -# This package is really more of a role, so it doesn't inherit from anything. +use Moose::Role; sub _inline_check_var_is_valid_key { my ( $self, $var ) = @_; @@ -18,4 +18,6 @@ sub _inline_check_var_is_valid_key { . qq{ unless defined $var;}; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm index c6828e6..4f83c07 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm @@ -9,14 +9,11 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; -Class::MOP::MiniTrait::apply( __PACKAGE__, - 'Moose::Meta::Method::Accessor::Native::Hash' -); -Class::MOP::MiniTrait::apply( __PACKAGE__, - 'Moose::Meta::Method::Accessor::Native::Collection' -); +with 'Moose::Meta::Method::Accessor::Native::Writer', + 'Moose::Meta::Method::Accessor::Native::Hash', + 'Moose::Meta::Method::Accessor::Native::Collection'; sub _new_values {'@values'} @@ -26,4 +23,6 @@ sub _inline_copy_old_value { return '{ %{' . $slot_access . '} }'; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm index 3580dcb..a315b80 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm @@ -7,10 +7,30 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base qw( - Moose::Meta::Method::Accessor::Native::Hash::set - Moose::Meta::Method::Accessor::Native::Hash::get -); +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Hash::set' => { + -excludes => [ + qw( + _generate_method + _minimum_arguments + _maximum_arguments + _inline_check_arguments + _return_value + ) + ] + }, + 'Moose::Meta::Method::Accessor::Native::Hash::get' => { + -excludes => [ + qw( + _generate_method + _minimum_arguments + _maximum_arguments + _inline_check_argument_count + _inline_process_arguments + ) + ] + }; sub _generate_method { my $self = shift; @@ -58,8 +78,6 @@ sub _generate_method { sub _minimum_arguments {2} sub _maximum_arguments {2} -sub _adds_members {1} - -sub _new_members {'$_[1]'} +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/clear.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/clear.pm index 0998878..74593a6 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/clear.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/clear.pm @@ -7,7 +7,16 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Hash::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Hash::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _maximum_arguments { 0 } @@ -21,4 +30,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = {}"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/count.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/count.pm index 876282e..c0d74d5 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/count.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/count.pm @@ -9,9 +9,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; -sub _minimum_arguments { 0 } +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -22,5 +23,6 @@ sub _return_value { return "scalar keys \%{ $slot_access }"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/defined.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/defined.pm index cc192ff..7890535 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/defined.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/defined.pm @@ -9,10 +9,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base qw( - Moose::Meta::Method::Accessor::Native::Hash - Moose::Meta::Method::Accessor::Native::Reader -); +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ], + }, + 'Moose::Meta::Method::Accessor::Native::Hash'; sub _minimum_arguments { 1 } @@ -31,5 +39,6 @@ sub _return_value { return "defined ${slot_access}->{ \$_[0] }"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/delete.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/delete.pm index 17a4f93..7531716 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/delete.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/delete.pm @@ -7,7 +7,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Hash::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Hash::Writer' => + { -excludes => ['_inline_optimized_set_new_value'] }; sub _adds_members { 0 } @@ -23,4 +26,6 @@ sub _inline_optimized_set_new_value { return "delete \@{ $slot_access }{\@_}"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/elements.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/elements.pm index 74f42bb..394d207 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/elements.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/elements.pm @@ -9,9 +9,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; -sub _minimum_arguments { 0 } +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -22,5 +23,6 @@ sub _return_value { return "map { \$_, ${slot_access}->{\$_} } keys \%{ $slot_access }"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/exists.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/exists.pm index 0d83b77..f0f291e 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/exists.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/exists.pm @@ -9,10 +9,18 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base qw( - Moose::Meta::Method::Accessor::Native::Hash - Moose::Meta::Method::Accessor::Native::Reader -); +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ], + }, + 'Moose::Meta::Method::Accessor::Native::Hash'; sub _minimum_arguments { 1 } @@ -31,5 +39,6 @@ sub _return_value { return "exists ${slot_access}->{ \$_[0] }"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/get.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/get.pm index 29d22bb..473594d 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/get.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/get.pm @@ -9,16 +9,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; - -Class::MOP::MiniTrait::apply( __PACKAGE__, - 'Moose::Meta::Method::Accessor::Native::Hash' -); +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _inline_check_arguments + ) + ], + }, + 'Moose::Meta::Method::Accessor::Native::Hash'; sub _minimum_arguments { 1 } -sub _maximum_arguments { undef } - sub _inline_check_arguments { my $self = shift; @@ -34,5 +38,6 @@ sub _return_value { return "\@_ > 1 ? \@{ $slot_access }{\@_} : ${slot_access}->{ \$_[0] }"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/is_empty.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/is_empty.pm index 8204220..b6a3fc6 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/is_empty.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/is_empty.pm @@ -9,9 +9,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; -sub _minimum_arguments { 0 } +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -22,5 +23,6 @@ sub _return_value { return "scalar keys \%{ $slot_access } ? 0 : 1"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/keys.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/keys.pm index f28c6b2..9292057 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/keys.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/keys.pm @@ -9,9 +9,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; -sub _minimum_arguments { 0 } +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -22,5 +23,6 @@ sub _return_value { return "keys \%{ $slot_access }"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/kv.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/kv.pm index ccbf919..a986e03 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/kv.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/kv.pm @@ -9,9 +9,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; -sub _minimum_arguments { 0 } +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -22,5 +23,6 @@ sub _return_value { return "map { [ \$_, ${slot_access}->{\$_} ] } keys \%{ $slot_access }"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/set.pm index 7e35f5d..99f9ccb 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/set.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/set.pm @@ -9,21 +9,34 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Hash::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Hash::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_process_arguments + _inline_check_arguments + _inline_optimized_set_new_value + ) + ], +}; sub _minimum_arguments { 2 } sub _maximum_arguments { undef } -sub _inline_check_argument_count { +around _inline_check_argument_count => sub { + my $orig = shift; my $self = shift; return - $self->SUPER::_inline_check_argument_count(@_) . "\n" + $self->$orig(@_) . "\n" . $self->_inline_throw_error( q{'You must pass an even number of arguments to set'}) . ' if @_ % 2;'; -} +}; sub _inline_process_arguments { my $self = shift; @@ -58,4 +71,6 @@ sub _inline_optimized_set_new_value { return "\@{ $slot_access }{ \@_[ \@keys_idx] } = \@_[ \@values_idx ]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/values.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/values.pm index 910639b..cbfd0c0 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/values.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/values.pm @@ -9,9 +9,10 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; -sub _minimum_arguments { 0 } +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; sub _maximum_arguments { 0 } @@ -22,5 +23,6 @@ sub _return_value { return "values \%{ $slot_access }"; } +no Moose::Role; 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm index ebeb683..cfdb9df 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/abs.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments {0} sub _maximum_arguments {0} sub _potential_value { @@ -24,4 +32,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = abs($slot_access)"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm index 01b8788..2a405c8 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/add.pm @@ -7,9 +7,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments {1} + sub _maximum_arguments {1} sub _potential_value { @@ -24,4 +35,6 @@ sub _inline_optimized_set_new_value { return "$slot_access += \$_[0]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm index eafdb96..a17fb84 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/div.pm @@ -7,9 +7,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments {1} + sub _maximum_arguments {1} sub _potential_value { @@ -24,4 +35,6 @@ sub _inline_optimized_set_new_value { return "$slot_access /= \$_[0]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm index 823c553..68a0ceb 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/mod.pm @@ -7,9 +7,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments {1} + sub _maximum_arguments {1} sub _potential_value { @@ -24,4 +35,6 @@ sub _inline_optimized_set_new_value { return "$slot_access %= \$_[0]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm index b0d0704..f49b639 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/mul.pm @@ -7,9 +7,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments {1} + sub _maximum_arguments {1} sub _potential_value { @@ -24,4 +35,6 @@ sub _inline_optimized_set_new_value { return "$slot_access *= \$_[0]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm index b76efb3..1559877 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/set.pm @@ -7,7 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments {1} sub _maximum_arguments {1} @@ -20,4 +30,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = \$_[0]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm b/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm index ee145f5..e051368 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Number/sub.pm @@ -7,9 +7,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments {1} + sub _maximum_arguments {1} sub _potential_value { @@ -24,4 +35,6 @@ sub _inline_optimized_set_new_value { return "$slot_access -= \$_[0]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Reader.pm b/lib/Moose/Meta/Method/Accessor/Native/Reader.pm index 2d4a9f6..b0c1c45 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Reader.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Reader.pm @@ -7,7 +7,11 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native'; + +requires '_return_value'; sub _generate_method { my $self = shift; @@ -48,10 +52,14 @@ sub _reader_core { sub _inline_process_arguments {q{}} +sub _inline_check_arguments {q{}} + sub _inline_return_value { my ( $self, $slot_access ) = @_; 'return ' . $self->_return_value($slot_access) . ';'; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/append.pm b/lib/Moose/Meta/Method/Accessor/Native/String/append.pm index 94bbd96..ff17db5 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/append.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/append.pm @@ -7,9 +7,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments { 1 } + sub _maximum_arguments { 1 } sub _potential_value { @@ -24,4 +35,6 @@ sub _inline_optimized_set_new_value { return "$slot_access .= \$_[0]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm b/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm index 24a5cb1..020165a 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/chomp.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _potential_value { @@ -24,4 +32,6 @@ sub _inline_optimized_set_new_value { return "chomp $slot_access"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/chop.pm b/lib/Moose/Meta/Method/Accessor/Native/String/chop.pm index e724ab0..f9b1ac0 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/chop.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/chop.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _potential_value { @@ -24,4 +32,6 @@ sub _inline_optimized_set_new_value { return "chop $slot_access"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm b/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm index 5a4e3a5..06823b7 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/clear.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _potential_value { @@ -24,4 +32,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = q{}"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/inc.pm b/lib/Moose/Meta/Method/Accessor/Native/String/inc.pm index 9757b5a..4e1ca51 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/inc.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/inc.pm @@ -7,9 +7,17 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _potential_value { @@ -24,4 +32,6 @@ sub _inline_optimized_set_new_value { return "${slot_access}++"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/length.pm b/lib/Moose/Meta/Method/Accessor/Native/String/length.pm index 24d9a84..134619a 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/length.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/length.pm @@ -7,9 +7,11 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => + { -excludes => ['_maximum_arguments'] }; -sub _minimum_arguments { 0 } sub _maximum_arguments { 0 } sub _return_value { @@ -18,4 +20,6 @@ sub _return_value { return "length $slot_access"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/match.pm b/lib/Moose/Meta/Method/Accessor/Native/String/match.pm index 13817fe..23492e7 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/match.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/match.pm @@ -7,9 +7,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _minimum_arguments { 1 } + sub _maximum_arguments { 1 } sub _inline_check_arguments { @@ -26,4 +37,6 @@ sub _return_value { return "$slot_access =~ \$_[0]"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm b/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm index d3af464..6944a71 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/prepend.pm @@ -7,9 +7,20 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments { 1 } + sub _maximum_arguments { 1 } sub _potential_value { @@ -24,4 +35,6 @@ sub _inline_optimized_set_new_value { return "$slot_access = \$_[0] . $slot_access"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/replace.pm b/lib/Moose/Meta/Method/Accessor/Native/String/replace.pm index bb8c308..5650fc0 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/replace.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/replace.pm @@ -7,9 +7,21 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native::Writer'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _minimum_arguments + _maximum_arguments + _inline_check_arguments + _inline_optimized_set_new_value + ) + ] +}; sub _minimum_arguments { 1 } + sub _maximum_arguments { 2 } sub _inline_check_arguments { @@ -36,4 +48,6 @@ sub _inline_optimized_set_new_value { return "if ( ref \$_[1] ) { $slot_access =~ s/\$_[0]/\$_[1]->()/e; } else { $slot_access =~ s/\$_[0]/\$_[1]/; }"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm b/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm index ab25e23..9f5d8c8 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/String/substr.pm @@ -7,10 +7,32 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base qw( - Moose::Meta::Method::Accessor::Native::Reader - Moose::Meta::Method::Accessor::Native::Writer -); +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( _generate_method + _minimum_arguments + _maximum_arguments + _inline_process_arguments + _inline_check_arguments + _return_value + ) + ] + }, + 'Moose::Meta::Method::Accessor::Native::Writer' => { + -excludes => [ + qw( + _generate_method + _minimum_arguments + _maximum_arguments + _inline_process_arguments + _inline_check_arguments + _inline_optimized_set_new_value + _return_value + ) + ] + }; sub _generate_method { my $self = shift; @@ -101,4 +123,6 @@ sub _return_value { return "substr $slot_access, \$offset, \$length"; } +no Moose::Role; + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Writer.pm index f44aac4..60f1d01 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Writer.pm @@ -9,7 +9,11 @@ our $VERSION = '1.14'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor::Native'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native'; + +requires '_potential_value'; sub _generate_method { my $self = shift; @@ -130,31 +134,33 @@ sub _inline_check_coercion { return "$value = \$type_constraint_obj->coerce($value);"; } -sub _inline_check_constraint { +override _inline_check_constraint => sub { my $self = shift; return q{} unless $self->_constraint_must_be_checked; - return $self->SUPER::_inline_check_constraint( $_[0] ); -} + return super(); +}; sub _inline_capture_return_value { return q{} } sub _inline_set_new_value { my $self = shift; - return $self->SUPER::_inline_store(@_) + return $self->_inline_store(@_) if $self->_value_needs_copy || !$self->_slot_access_can_be_inlined; return $self->_inline_optimized_set_new_value(@_); -} +}; sub _inline_optimized_set_new_value { my $self = shift; - return $self->SUPER::_inline_store(@_) + return $self->_inline_store(@_); } sub _return_value { return q{} } +no Moose::Role; + 1; diff --git a/t/070_native_traits/010_trait_array.t b/t/070_native_traits/010_trait_array.t index 233640d..58df448 100644 --- a/t/070_native_traits/010_trait_array.t +++ b/t/070_native_traits/010_trait_array.t @@ -3,8 +3,12 @@ use strict; use warnings; +use lib 't/lib'; + use Moose (); +use Moose::Util::MetaRole; use Moose::Util::TypeConstraints; +use NoInlineAttribute; use Test::More; use Test::Exception; use Test::Moose; @@ -70,9 +74,13 @@ use Test::Moose; superclasses => ['Moose::Object'], ); + my @traits = 'Array'; + push @traits, 'NoInlineAttribute' + if delete $attr{no_inline}; + $class->add_attribute( _values => ( - traits => ['Array'], + traits => \@traits, is => 'rw', isa => 'ArrayRef[Int]', default => sub { [] }, @@ -90,6 +98,7 @@ use Test::Moose; run_tests(build_class); run_tests( build_class( lazy => 1, default => sub { [ 42, 84 ] } ) ); run_tests( build_class( trigger => sub { } ) ); + run_tests( build_class( no_inline => 1 ) ); # Will force the inlining code to check the entire arrayref when it is modified. subtype 'MyArrayRef', as 'ArrayRef', where { 1 }; @@ -279,6 +288,10 @@ sub run_tests { 'values is not empty after failed call to clear' ); + throws_ok { $obj->is_empty(50) } + qr/Cannot call is_empty with any arguments/, + 'throws an error when is_empty is called with an argument'; + $obj->clear; $obj->push( 1, 5, 10, 42 ); diff --git a/t/070_native_traits/020_trait_bool.t b/t/070_native_traits/020_trait_bool.t index 7307011..b749895 100644 --- a/t/070_native_traits/020_trait_bool.t +++ b/t/070_native_traits/020_trait_bool.t @@ -3,8 +3,11 @@ use strict; use warnings; +use lib 't/lib'; + use Moose (); use Moose::Util::TypeConstraints; +use NoInlineAttribute; use Test::More; use Test::Exception; use Test::Moose; @@ -27,9 +30,13 @@ use Test::Moose; superclasses => ['Moose::Object'], ); + my @traits = 'Bool'; + push @traits, 'NoInlineAttribute' + if delete $attr{no_inline}; + $class->add_attribute( is_lit => ( - traits => ['Bool'], + traits => \@traits, is => 'rw', isa => 'Bool', default => 0, @@ -47,6 +54,7 @@ use Test::Moose; run_tests(build_class); run_tests( build_class( lazy => 1 ) ); run_tests( build_class( trigger => sub { } ) ); + run_tests( build_class( no_inline => 1 ) ); # Will force the inlining code to check the entire hashref when it is modified. subtype 'MyBool', as 'Bool', where { 1 }; diff --git a/t/070_native_traits/030_trait_code.t b/t/070_native_traits/030_trait_code.t index ebaf17b..3f58b57 100644 --- a/t/070_native_traits/030_trait_code.t +++ b/t/070_native_traits/030_trait_code.t @@ -1,7 +1,10 @@ use strict; use warnings; +use lib 't/lib'; + use Moose (); +use NoInlineAttribute; use Test::More; use Test::Exception; use Test::Moose; @@ -10,16 +13,20 @@ use Test::Moose; my $name = 'Foo1'; sub build_class { - my ( $attr1, $attr2, $attr3 ) = @_; + my ( $attr1, $attr2, $attr3, $no_inline ) = @_; my $class = Moose::Meta::Class->create( $name++, superclasses => ['Moose::Object'], ); + my @traits = 'Code'; + push @traits, 'NoInlineAttribute' + if $no_inline; + $class->add_attribute( callback => ( - traits => ['Code'], + traits => \@traits, isa => 'CodeRef', required => 1, handles => { 'invoke_callback' => 'execute' }, @@ -29,7 +36,7 @@ use Test::Moose; $class->add_attribute( callback_method => ( - traits => ['Code'], + traits => \@traits, isa => 'CodeRef', required => 1, handles => { 'invoke_method_callback' => 'execute_method' }, @@ -39,7 +46,7 @@ use Test::Moose; $class->add_attribute( multiplier => ( - traits => ['Code'], + traits => \@traits, isa => 'CodeRef', required => 1, handles => { 'multiply' => 'execute' }, @@ -62,6 +69,8 @@ use Test::Moose; run_tests( build_class, \$i, \%subs ); + run_tests( build_class( undef, undef, undef, 1 ), \$i, \%subs ); + run_tests( build_class( { diff --git a/t/070_native_traits/040_trait_counter.t b/t/070_native_traits/040_trait_counter.t index 3f6ca1a..a20e5c2 100644 --- a/t/070_native_traits/040_trait_counter.t +++ b/t/070_native_traits/040_trait_counter.t @@ -3,8 +3,11 @@ use strict; use warnings; +use lib 't/lib'; + use Moose (); use Moose::Util::TypeConstraints; +use NoInlineAttribute; use Test::Exception; use Test::More; use Test::Moose; @@ -30,9 +33,13 @@ use Test::Moose; superclasses => ['Moose::Object'], ); + my @traits = 'Counter'; + push @traits, 'NoInlineAttribute' + if delete $attr{no_inline}; + $class->add_attribute( counter => ( - traits => ['Counter'], + traits => \@traits, is => 'ro', isa => 'Int', default => 0, @@ -50,6 +57,7 @@ use Test::Moose; run_tests(build_class); run_tests( build_class( lazy => 1 ) ); run_tests( build_class( trigger => sub { } ) ); + run_tests( build_class( no_inline => 1 ) ); # Will force the inlining code to check the entire hashref when it is modified. subtype 'MyInt', as 'Int', where { 1 }; diff --git a/t/070_native_traits/050_trait_hash.t b/t/070_native_traits/050_trait_hash.t index 63582c5..5b7cd19 100644 --- a/t/070_native_traits/050_trait_hash.t +++ b/t/070_native_traits/050_trait_hash.t @@ -3,8 +3,11 @@ use strict; use warnings; +use lib 't/lib'; + use Moose (); use Moose::Util::TypeConstraints; +use NoInlineAttribute; use Test::Exception; use Test::More; use Test::Moose; @@ -35,9 +38,13 @@ use Test::Moose; superclasses => ['Moose::Object'], ); + my @traits = 'Hash'; + push @traits, 'NoInlineAttribute' + if delete $attr{no_inline}; + $class->add_attribute( options => ( - traits => ['Hash'], + traits => \@traits, is => 'ro', isa => 'HashRef[Str]', default => sub { {} }, @@ -55,6 +62,7 @@ use Test::Moose; run_tests(build_class); run_tests( build_class( lazy => 1, default => sub { { x => 1 } } ) ); run_tests( build_class( trigger => sub { } ) ); + run_tests( build_class( no_inline => 1 ) ); # Will force the inlining code to check the entire hashref when it is modified. subtype 'MyHashRef', as 'HashRef[Str]', where { 1 }; diff --git a/t/070_native_traits/060_trait_number.t b/t/070_native_traits/060_trait_number.t index cfcd4fe..7eef720 100644 --- a/t/070_native_traits/060_trait_number.t +++ b/t/070_native_traits/060_trait_number.t @@ -3,8 +3,11 @@ use strict; use warnings; +use lib 't/lib'; + use Moose (); use Moose::Util::TypeConstraints; +use NoInlineAttribute; use Test::Exception; use Test::More; use Test::Moose; @@ -34,9 +37,13 @@ use Test::Moose; superclasses => ['Moose::Object'], ); + my @traits = 'Number'; + push @traits, 'NoInlineAttribute' + if delete $attr{no_inline}; + $class->add_attribute( integer => ( - traits => ['Number'], + traits => \@traits, is => 'ro', isa => 'Int', default => 5, @@ -54,6 +61,7 @@ use Test::Moose; run_tests(build_class); run_tests( build_class( lazy => 1 ) ); run_tests( build_class( trigger => sub { } ) ); + run_tests( build_class( no_inline => 1 ) ); # Will force the inlining code to check the entire hashref when it is modified. subtype 'MyInt', as 'Int', where { 1 }; diff --git a/t/070_native_traits/070_trait_string.t b/t/070_native_traits/070_trait_string.t index 5740906..f5d4ab7 100644 --- a/t/070_native_traits/070_trait_string.t +++ b/t/070_native_traits/070_trait_string.t @@ -3,8 +3,11 @@ use strict; use warnings; +use lib 't/lib'; + use Moose (); use Moose::Util::TypeConstraints; +use NoInlineAttribute; use Test::More; use Test::Exception; use Test::Moose; @@ -40,9 +43,13 @@ use Test::Moose; superclasses => ['Moose::Object'], ); + my @traits = 'String'; + push @traits, 'NoInlineAttribute' + if delete $attr{no_inline}; + $class->add_attribute( _string => ( - traits => ['String'], + traits => \@traits, is => 'rw', isa => 'Str', default => q{}, @@ -60,6 +67,7 @@ use Test::Moose; run_tests(build_class); run_tests( build_class( lazy => 1, default => q{} ) ); run_tests( build_class( trigger => sub { } ) ); + run_tests( build_class( no_inline => 1 ) ); # Will force the inlining code to check the entire hashref when it is modified. subtype 'MyStr', as 'Str', where { 1 }; diff --git a/t/lib/NoInlineAttribute.pm b/t/lib/NoInlineAttribute.pm new file mode 100644 index 0000000..af182dc --- /dev/null +++ b/t/lib/NoInlineAttribute.pm @@ -0,0 +1,29 @@ +package NoInlineAttribute; + +use Moose::Meta::Class; +use Moose::Role; + +around accessor_metaclass => sub { + my $orig = shift; + my $self = shift; + + my $class = $self->$orig(); + + return Moose::Meta::Class->create_anon_class( + superclasses => [$class], + roles => ['NoInlineAccessor'], + cache => 1, + )->name; +}; + +no Moose::Role; + +{ + package NoInlineAccessor; + + use Moose::Role; + + sub is_inline { 0 } +} + +1;