Add semi-colon in code that generates entire assignment, which makes snippets more...
[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.14';
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
24           $self->_inline_check_var_is_valid_index('$idx') . "\n"
25         . $self->_inline_throw_error(q{'The length argument passed to splice must be an integer'})
26         . ' if defined $len && $len !~ /^-?\\d+$/;';
27 }
28
29 sub _potential_value {
30     my ( $self, $slot_access ) = @_;
31
32     return "( do { my \@potential = \@{ $slot_access };"
33         . 'defined $len ? ( splice @potential, $idx, $len, @_ ) : ( splice @potential, $idx ); \\@potential } )';
34 }
35
36 sub _inline_optimized_set_new_value {
37     my ( $self, $inv, $new, $slot_access ) = @_;
38
39     return "defined \$len ? ( splice \@{ $slot_access }, \$idx, \$len, \@_ ) : ( splice \@{ $slot_access }, \$idx )";
40 }
41
42 1;