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