All native array methods are being inlined.
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array.pm
CommitLineData
f7fd22b6 1package Moose::Meta::Method::Accessor::Native::Array;
2
3use strict;
4use warnings;
5
6use B;
7use Scalar::Util qw( looks_like_number );
8
9our $VERSION = '1.13';
10$VERSION = eval $VERSION;
11our $AUTHORITY = 'cpan:STEVAN';
12
13use base 'Moose::Meta::Method::Accessor::Native';
14
f5f08b5f 15sub _inline_curried_arguments {
f7fd22b6 16 my $self = shift;
17
f5f08b5f 18 return q{} unless @{ $self->curried_arguments };
f7fd22b6 19
aada334d 20 return 'unshift @_, @curried;'
f7fd22b6 21}
22
a7821be5 23sub _inline_check_argument_count {
f7fd22b6 24 my $self = shift;
25
a7821be5 26 my $code = q{};
27
28 if ( my $min = $self->_minimum_arguments ) {
29 my $err_msg = sprintf(
30 q{"Cannot call %s without at least %s argument%s"},
31 $self->delegate_to_method,
32 $min,
33 ( $min == 1 ? q{} : 's' )
34 );
35
36 $code
37 .= "\n"
38 . $self->_inline_throw_error($err_msg)
39 . " unless \@_ >= $min;";
40 }
41
42 if ( defined( my $max = $self->_maximum_arguments ) ) {
43 my $err_msg = sprintf(
44 q{"Cannot call %s with %s argument%s"},
45 $self->delegate_to_method,
46 ( $max ? "more than $max" : 'any' ),
47 ( $max == 1 ? q{} : 's' )
48 );
49
50 $code
51 .= "\n"
52 . $self->_inline_throw_error($err_msg)
53 . " if \@_ > $max;";
54 }
55
56 return $code;
f7fd22b6 57}
58
a7821be5 59sub _minimum_arguments { 0 }
60sub _maximum_arguments { undef }
f7fd22b6 61
a7821be5 62sub _inline_check_arguments { q{} }
f7fd22b6 63
a7821be5 64sub _inline_check_var_is_valid_index {
65 my ( $self, $var ) = @_;
910684ee 66
a7821be5 67 return
68 qq{die 'Must provide a valid index number as an argument' unless defined $var && $var =~ /^-?\\d+\$/;};
69}
910684ee 70
f7fd22b6 711;