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';
12 use base 'Moose::Meta::Method::Accessor::Native::Hash::Writer';
14 sub _minimum_arguments { 2 }
16 sub _maximum_arguments { undef }
18 sub _inline_check_argument_count {
22 $self->SUPER::_inline_check_argument_count(@_) . "\n"
23 . $self->_inline_throw_error(
24 q{'You must pass an even number of arguments to set'})
28 sub _inline_process_arguments {
31 return 'my @keys_idx = grep { ! ($_ % 2) } 0..$#_;' . "\n"
32 . 'my @values_idx = grep { $_ % 2 } 0..$#_;';
35 sub _inline_check_arguments {
39 'for (@keys_idx) {' . "\n"
40 . $self->_inline_throw_error(
41 q{'Hash keys passed to set must be defined'})
42 . ' unless defined $_[$_];' . "\n" . '}';
45 sub _adds_members { 1 }
47 sub _potential_value {
48 my ( $self, $slot_access ) = @_;
50 return "{ %{ $slot_access }, \@_ }";
53 sub _new_members { '@_[ @values_idx ]' }
55 sub _inline_optimized_set_new_value {
56 my ( $self, $inv, $new, $slot_access ) = @_;
58 return "\@{ $slot_access }{ \@_[ \@keys_idx] } = \@_[ \@values_idx ];";