bump version to 1.25
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / splice.pm
CommitLineData
a7821be5 1package Moose::Meta::Method::Accessor::Native::Array::splice;
2
3use strict;
4use warnings;
5
0c3879e8 6our $VERSION = '1.25';
a7821be5 7$VERSION = eval $VERSION;
8our $AUTHORITY = 'cpan:STEVAN';
9
8b9641b8 10use Moose::Role;
11
12with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => {
13 -excludes => [
14 qw(
15 _minimum_arguments
16 _inline_process_arguments
17 _inline_check_arguments
18 _inline_optimized_set_new_value
7f5ec80d 19 _return_value
8b9641b8 20 )
21 ]
22};
a7821be5 23
24sub _minimum_arguments { 1 }
25
26sub _adds_members { 1 }
27
28sub _inline_process_arguments {
29 return 'my $idx = shift;' . "\n" . 'my $len = @_ ? shift : undef;';
30}
31
32sub _inline_check_arguments {
33 my $self = shift;
34
e3181911 35 return
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+$/;';
a7821be5 39}
40
41sub _potential_value {
42 my ( $self, $slot_access ) = @_;
43
1d06edbf 44 return "( do { my \@potential = \@{ ($slot_access) };"
7f5ec80d 45 . '@return = defined $len ? ( splice @potential, $idx, $len, @_ ) : ( splice @potential, $idx ); \\@potential } )';
e32b7489 46}
47
48sub _inline_optimized_set_new_value {
49 my ( $self, $inv, $new, $slot_access ) = @_;
50
1d06edbf 51 return "\@return = defined \$len ? ( splice \@{ ($slot_access) }, \$idx, \$len, \@_ ) : ( splice \@{ ($slot_access) }, \$idx )";
7f5ec80d 52}
53
54sub _return_value {
55 my ($self, $slot_access) = @_;
56
57 return 'return wantarray ? @return : $return[-1]';
a7821be5 58}
59
8b9641b8 60no Moose::Role;
61
a7821be5 621;