All native array methods are being inlined.
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / splice.pm
1 package Moose::Meta::Method::Accessor::Native::Array::splice;
2
3 use strict;
4 use warnings;
5
6 our $VERSION = '1.13';
7 $VERSION = eval $VERSION;
8 our $AUTHORITY = 'cpan:STEVAN';
9
10 use base 'Moose::Meta::Method::Accessor::Native::Array::Writer';
11
12 sub _minimum_arguments { 1 }
13
14 sub _adds_members { 1 }
15
16 sub _inline_process_arguments {
17     return 'my $idx = shift;' . "\n" . 'my $len = @_ ? shift : undef;';
18 }
19
20 sub _inline_check_arguments {
21     my $self = shift;
22
23     return $self->_inline_check_var_is_valid_index('$idx') . "\n"
24         . q{die 'Length must an integer' if defined $len && $len !~ /^-?\\d+$/;};
25 }
26
27 sub _potential_value {
28     my ( $self, $slot_access ) = @_;
29
30     return "( do { my \@potential = \@{ $slot_access };"
31         . 'defined $len ? ( splice @potential, $idx, $len, @_ ) : ( splice @potential, $idx ); @potential } )';
32 }
33
34 1;