Commit | Line | Data |
---|---|---|
a7821be5 | 1 | package Moose::Meta::Method::Accessor::Native::Array::set; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
8b9641b8 | 6 | use Moose::Role; |
7 | ||
00bbc132 | 8 | with 'Moose::Meta::Method::Accessor::Native::Array::Writer'; |
a7821be5 | 9 | |
10 | sub _minimum_arguments { 2 } | |
11 | ||
12 | sub _maximum_arguments { 2 } | |
13 | ||
14 | sub _inline_check_arguments { | |
15 | my $self = shift; | |
16 | ||
17 | return $self->_inline_check_var_is_valid_index('$_[0]'); | |
18 | } | |
19 | ||
20 | sub _adds_members { 1 } | |
21 | ||
22 | sub _potential_value { | |
53a4677c | 23 | my $self = shift; |
24 | my ($slot_access) = @_; | |
a7821be5 | 25 | |
53a4677c | 26 | return '(do { ' |
27 | . 'my @potential = @{ (' . $slot_access . ') }; ' | |
28 | . '$potential[$_[0]] = $_[1]; ' | |
29 | . '\@potential; ' | |
30 | . '})'; | |
a7821be5 | 31 | } |
32 | ||
7bf5e58d | 33 | # We need to override this because while @_ can be written to, we cannot write |
34 | # directly to $_[1]. | |
53a4677c | 35 | sub _inline_coerce_new_values { |
7bf5e58d | 36 | my $self = shift; |
37 | ||
53a4677c | 38 | return unless $self->associated_attribute->should_coerce; |
7bf5e58d | 39 | |
53a4677c | 40 | return unless $self->_tc_member_type_can_coerce; |
7bf5e58d | 41 | |
ec02b571 | 42 | return '@_ = ($_[0], $member_coercion->($_[1]));'; |
7bf5e58d | 43 | }; |
44 | ||
44babf1f | 45 | sub _new_members { '$_[1]' } |
a7821be5 | 46 | |
a486d5ad | 47 | sub _inline_optimized_set_new_value { |
53a4677c | 48 | my $self = shift; |
49 | my ($inv, $new, $slot_access) = @_; | |
e32b7489 | 50 | |
a486d5ad | 51 | return $slot_access . '->[$_[0]] = $_[1];'; |
e32b7489 | 52 | } |
53 | ||
7f5ec80d | 54 | sub _return_value { |
53a4677c | 55 | my $self = shift; |
56 | my ($slot_access) = @_; | |
7f5ec80d | 57 | |
53a4677c | 58 | return $slot_access . '->[$_[0]]'; |
7f5ec80d | 59 | } |
60 | ||
8b9641b8 | 61 | no Moose::Role; |
62 | ||
a7821be5 | 63 | 1; |