Work in progress on inlining native traits methods.
[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
15sub _value_needs_copy {
16 my $self = shift;
17
18 return @{ $self->curried_arguments };
19}
20
21sub _inline_copy_value {
22 my $self = shift;
23
24 return q{} unless $self->_value_needs_copy;
25
26 my $curry = join ', ',
27 map { looks_like_number($_) ? $_ : B::perlstring($_) }
28 @{ $self->curried_arguments };
29
30 return "my \@val = ( $curry, \@_ );";
31}
32
33sub _inline_check_constraint {
34 my $self = shift;
35
36 return q{} unless $self->_constraint_must_be_checked;
37
38 return $self->SUPER::_inline_check_constraint(@_);
39}
40
41sub _constraint_must_be_checked {
42 my $self = shift;
43
44 my $attr = $self->associated_attribute;
45
46 return $attr->has_type_constraint
47 && ( $attr->type_constraint->name ne 'ArrayRef'
48 || ( $attr->should_coerce && $attr->type_constraint->has_coercion ) );
49}
50
511;