Commit | Line | Data |
a7821be5 |
1 | package Moose::Meta::Method::Accessor::Native::Array::set; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
3543f4d4 |
6 | our $VERSION = '1.23'; |
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 |
18 | _new_members |
19 | _inline_optimized_set_new_value |
7f5ec80d |
20 | _return_value |
8b9641b8 |
21 | ) |
22 | ] |
23 | }; |
a7821be5 |
24 | |
25 | sub _minimum_arguments { 2 } |
26 | |
27 | sub _maximum_arguments { 2 } |
28 | |
29 | sub _inline_check_arguments { |
30 | my $self = shift; |
31 | |
32 | return $self->_inline_check_var_is_valid_index('$_[0]'); |
33 | } |
34 | |
35 | sub _adds_members { 1 } |
36 | |
37 | sub _potential_value { |
38 | my ( $self, $slot_access ) = @_; |
39 | |
40 | return |
1d06edbf |
41 | "( do { my \@potential = \@{ ($slot_access) }; \$potential[ \$_[0] ] = \$_[1]; \\\@potential } )"; |
a7821be5 |
42 | } |
43 | |
7bf5e58d |
44 | # We need to override this because while @_ can be written to, we cannot write |
45 | # directly to $_[1]. |
46 | around _inline_coerce_new_values => sub { |
47 | shift; |
48 | my $self = shift; |
49 | |
50 | return q{} unless $self->associated_attribute->should_coerce; |
51 | |
52 | return q{} unless $self->_tc_member_type_can_coerce; |
53 | |
54 | return '@_ = ( $_[0], $member_tc_obj->coerce( $_[1] ) );'; |
55 | }; |
56 | |
44babf1f |
57 | sub _new_members { '$_[1]' } |
a7821be5 |
58 | |
e32b7489 |
59 | sub _inline_optimized_set_new_value { |
60 | my ( $self, $inv, $new, $slot_access ) = @_; |
61 | |
584540d9 |
62 | return "${slot_access}->[ \$_[0] ] = \$_[1]"; |
e32b7489 |
63 | } |
64 | |
7f5ec80d |
65 | sub _return_value { |
66 | my ( $self, $slot_access ) = @_; |
67 | |
68 | return "return ${slot_access}->[ \$_[0] ];"; |
69 | } |
70 | |
8b9641b8 |
71 | no Moose::Role; |
72 | |
a7821be5 |
73 | 1; |