Commit | Line | Data |
44babf1f |
1 | package Moose::Meta::Method::Accessor::Native::Hash::set; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Scalar::Util qw( looks_like_number ); |
7 | |
10bd99ec |
8 | our $VERSION = '1.14'; |
44babf1f |
9 | $VERSION = eval $VERSION; |
10 | our $AUTHORITY = 'cpan:STEVAN'; |
11 | |
12 | use base 'Moose::Meta::Method::Accessor::Native::Hash::Writer'; |
13 | |
14 | sub _minimum_arguments { 2 } |
15 | |
16 | sub _maximum_arguments { undef } |
17 | |
18 | sub _inline_check_argument_count { |
19 | my $self = shift; |
20 | |
21 | return |
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'}) |
25 | . ' if @_ % 2;'; |
26 | } |
27 | |
28 | sub _inline_process_arguments { |
29 | my $self = shift; |
30 | |
31 | return 'my @keys_idx = grep { ! ($_ % 2) } 0..$#_;' . "\n" |
32 | . 'my @values_idx = grep { $_ % 2 } 0..$#_;'; |
33 | } |
34 | |
35 | sub _inline_check_arguments { |
36 | my $self = shift; |
37 | |
38 | return |
39 | 'for (@keys_idx) {' . "\n" |
40 | . $self->_inline_throw_error( |
41 | q{'Hash keys passed to set must be defined'}) |
42 | . ' unless defined $_[$_];' . "\n" . '}'; |
43 | } |
44 | |
45 | sub _adds_members { 1 } |
46 | |
47 | sub _potential_value { |
48 | my ( $self, $slot_access ) = @_; |
49 | |
fe4e0a8c |
50 | return "{ %{ $slot_access }, \@_ }"; |
44babf1f |
51 | } |
52 | |
53 | sub _new_members { '@_[ @values_idx ]' } |
54 | |
55 | sub _inline_optimized_set_new_value { |
56 | my ( $self, $inv, $new, $slot_access ) = @_; |
57 | |
584540d9 |
58 | return "\@{ $slot_access }{ \@_[ \@keys_idx] } = \@_[ \@values_idx ]"; |
44babf1f |
59 | } |
60 | |
61 | 1; |