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