Bump version to 1.9900 for new version numbering scheme
[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
bb8ef151 6our $VERSION = '1.9900';
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
a486d5ad 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 {
53a4677c 29 return (
30 'my $idx = shift;',
31 'my $len = @_ ? shift : undef;',
32 );
a7821be5 33}
34
35sub _inline_check_arguments {
36 my $self = shift;
37
53a4677c 38 return (
39 $self->_inline_check_var_is_valid_index('$idx'),
40 'if (defined($len) && $len !~ /^-?\d+$/) {',
41 $self->_inline_throw_error(
42 '"The length argument passed to splice must be an integer"',
43 ) . ';',
44 '}',
45 );
a7821be5 46}
47
48sub _potential_value {
53a4677c 49 my $self = shift;
50 my ($slot_access) = @_;
51
52 return '(do { '
53 . 'my @potential = @{ (' . $slot_access . ') }; '
54 . '@return = defined $len '
55 . '? (splice @potential, $idx, $len, @_) '
56 . ': (splice @potential, $idx); '
57 . '\@potential;'
58 . '})';
e32b7489 59}
60
a486d5ad 61sub _inline_optimized_set_new_value {
53a4677c 62 my $self = shift;
63 my ($inv, $new, $slot_access) = @_;
e32b7489 64
a486d5ad 65 return (
66 '@return = defined $len',
67 '? (splice @{ (' . $slot_access . ') }, $idx, $len, @_)',
68 ': (splice @{ (' . $slot_access . ') }, $idx);',
69 );
7f5ec80d 70}
71
72sub _return_value {
53a4677c 73 my $self = shift;
74 my ($slot_access) = @_;
7f5ec80d 75
53a4677c 76 return 'wantarray ? @return : $return[-1]';
a7821be5 77}
78
8b9641b8 79no Moose::Role;
80
a7821be5 811;