Work in progress on inlining native traits methods.
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array.pm
1 package Moose::Meta::Method::Accessor::Native::Array;
2
3 use strict;
4 use warnings;
5
6 use B;
7 use Scalar::Util qw( looks_like_number );
8
9 our $VERSION = '1.13';
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
12
13 use base 'Moose::Meta::Method::Accessor::Native';
14
15 sub _value_needs_copy {
16     my $self = shift;
17
18     return @{ $self->curried_arguments };
19 }
20
21 sub _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
33 sub _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
41 sub _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
51 1;