X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FAccessor%2FNative%2FHash%2Fset.pm;h=1bb37cd5dd9803e651b9f6abf87302d3c7aa6f6b;hb=1d06edbfadf08687599bd8c8fd711f8c14cc2363;hp=89b238be77b1428ba99a6bacd4ef6f641b210249;hpb=fe4e0a8c56772d38e28a37a50f7da05da93e0d63;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/set.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/set.pm index 89b238b..1bb37cd 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/set.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/set.pm @@ -5,25 +5,39 @@ use warnings; use Scalar::Util qw( looks_like_number ); -our $VERSION = '1.14'; +our $VERSION = '1.16'; $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 + _return_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; @@ -47,7 +61,7 @@ sub _adds_members { 1 } sub _potential_value { my ( $self, $slot_access ) = @_; - return "{ %{ $slot_access }, \@_ }"; + return "{ %{ ($slot_access) }, \@_ }"; } sub _new_members { '@_[ @values_idx ]' } @@ -55,7 +69,15 @@ sub _new_members { '@_[ @values_idx ]' } sub _inline_optimized_set_new_value { my ( $self, $inv, $new, $slot_access ) = @_; - return "\@{ $slot_access }{ \@_[ \@keys_idx] } = \@_[ \@values_idx ];"; + return "\@{ ($slot_access) }{ \@_[ \@keys_idx] } = \@_[ \@values_idx ]"; +} + +sub _return_value { + my ( $self, $slot_access ) = @_; + + return "return wantarray ? \@{ ($slot_access) }{ \@_[ \@keys_idx ] } : ${slot_access}->{ \$_[ \$keys_idx[0] ] };"; } +no Moose::Role; + 1;