1 package Moose::Meta::Method::Accessor::Native::Hash::set;
6 use Scalar::Util qw( looks_like_number );
9 $VERSION = eval $VERSION;
10 our $AUTHORITY = 'cpan:STEVAN';
14 with 'Moose::Meta::Method::Accessor::Native::Hash::Writer' => {
19 _inline_process_arguments
20 _inline_check_arguments
21 _inline_optimized_set_new_value
27 sub _minimum_arguments { 2 }
29 sub _maximum_arguments { undef }
31 around _inline_check_argument_count => sub {
36 $self->$orig(@_) . "\n"
37 . $self->_inline_throw_error(
38 q{'You must pass an even number of arguments to set'})
42 sub _inline_process_arguments {
45 return 'my @keys_idx = grep { ! ($_ % 2) } 0..$#_;' . "\n"
46 . 'my @values_idx = grep { $_ % 2 } 0..$#_;';
49 sub _inline_check_arguments {
53 'for (@keys_idx) {' . "\n"
54 . $self->_inline_throw_error(
55 q{'Hash keys passed to set must be defined'})
56 . ' unless defined $_[$_];' . "\n" . '}';
59 sub _adds_members { 1 }
61 sub _potential_value {
62 my ( $self, $slot_access ) = @_;
64 return "{ %{ $slot_access }, \@_ }";
67 sub _new_members { '@_[ @values_idx ]' }
69 sub _inline_optimized_set_new_value {
70 my ( $self, $inv, $new, $slot_access ) = @_;
72 return "\@{ $slot_access }{ \@_[ \@keys_idx] } = \@_[ \@values_idx ]";
76 my ( $self, $slot_access ) = @_;
78 return "return wantarray ? \@{ $slot_access }{ \@_[ \@keys_idx ] } : ${slot_access}->{ \$_[ \$keys_idx[0] ] };";