Commit | Line | Data |
a7821be5 |
1 | package Moose::Meta::Method::Accessor::Native::Array::splice; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
10bd99ec |
6 | our $VERSION = '1.14'; |
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 | _inline_process_arguments |
17 | _inline_check_arguments |
18 | _inline_optimized_set_new_value |
19 | ) |
20 | ] |
21 | }; |
a7821be5 |
22 | |
23 | sub _minimum_arguments { 1 } |
24 | |
25 | sub _adds_members { 1 } |
26 | |
27 | sub _inline_process_arguments { |
28 | return 'my $idx = shift;' . "\n" . 'my $len = @_ ? shift : undef;'; |
29 | } |
30 | |
31 | sub _inline_check_arguments { |
32 | my $self = shift; |
33 | |
e3181911 |
34 | return |
35 | $self->_inline_check_var_is_valid_index('$idx') . "\n" |
36 | . $self->_inline_throw_error(q{'The length argument passed to splice must be an integer'}) |
37 | . ' if defined $len && $len !~ /^-?\\d+$/;'; |
a7821be5 |
38 | } |
39 | |
40 | sub _potential_value { |
41 | my ( $self, $slot_access ) = @_; |
42 | |
43 | return "( do { my \@potential = \@{ $slot_access };" |
e32b7489 |
44 | . 'defined $len ? ( splice @potential, $idx, $len, @_ ) : ( splice @potential, $idx ); \\@potential } )'; |
45 | } |
46 | |
47 | sub _inline_optimized_set_new_value { |
48 | my ( $self, $inv, $new, $slot_access ) = @_; |
49 | |
584540d9 |
50 | return "defined \$len ? ( splice \@{ $slot_access }, \$idx, \$len, \@_ ) : ( splice \@{ $slot_access }, \$idx )"; |
a7821be5 |
51 | } |
52 | |
8b9641b8 |
53 | no Moose::Role; |
54 | |
a7821be5 |
55 | 1; |