1 package Moose::Meta::Method::Accessor::Native::Array::splice;
7 $VERSION = eval $VERSION;
8 our $AUTHORITY = 'cpan:STEVAN';
12 with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => {
16 _inline_process_arguments
17 _inline_check_arguments
18 _inline_optimized_set_new_value
24 sub _minimum_arguments { 1 }
26 sub _adds_members { 1 }
28 sub _inline_process_arguments {
29 return 'my $idx = shift;' . "\n" . 'my $len = @_ ? shift : undef;';
32 sub _inline_check_arguments {
36 $self->_inline_check_var_is_valid_index('$idx') . "\n"
37 . $self->_inline_throw_error(q{'The length argument passed to splice must be an integer'})
38 . ' if defined $len && $len !~ /^-?\\d+$/;';
41 sub _potential_value {
42 my ( $self, $slot_access ) = @_;
44 return "( do { my \@potential = \@{ ($slot_access) };"
45 . '@return = defined $len ? ( splice @potential, $idx, $len, @_ ) : ( splice @potential, $idx ); \\@potential } )';
48 sub _inline_optimized_set_new_value {
49 my ( $self, $inv, $new, $slot_access ) = @_;
51 return "\@return = defined \$len ? ( splice \@{ ($slot_access) }, \$idx, \$len, \@_ ) : ( splice \@{ ($slot_access) }, \$idx )";
55 my ($self, $slot_access) = @_;
57 return 'return wantarray ? @return : $return[-1]';