Never use die in generate code when throwing an error.
[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
6our $VERSION = '1.13';
7$VERSION = eval $VERSION;
8our $AUTHORITY = 'cpan:STEVAN';
9
10use base 'Moose::Meta::Method::Accessor::Native::Array::Writer';
11
12sub _minimum_arguments { 1 }
13
14sub _adds_members { 1 }
15
16sub _inline_process_arguments {
17 return 'my $idx = shift;' . "\n" . 'my $len = @_ ? shift : undef;';
18}
19
20sub _inline_check_arguments {
21 my $self = shift;
22
e3181911 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+$/;';
a7821be5 27}
28
29sub _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
361;