make native trait inlining work
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / pop.pm
1 package Moose::Meta::Method::Accessor::Native::Array::pop;
2
3 use strict;
4 use warnings;
5
6 our $VERSION = '1.19';
7 $VERSION = eval $VERSION;
8 our $AUTHORITY = 'cpan:STEVAN';
9
10 use Moose::Role;
11
12 with 'Moose::Meta::Method::Accessor::Native::Array::Writer' => {
13     -excludes => [
14         qw( _maximum_arguments
15             _inline_capture_return_value
16             _optimized_set_new_value
17             _return_value )
18     ]
19 };
20
21 sub _maximum_arguments { 0 }
22
23 sub _adds_members { 0 }
24
25 sub _potential_value {
26     my $self = shift;
27     my ($slot_access) = @_;
28
29     return '[ @{ (' . $slot_access . ') } > 1 '
30              . '? @{ (' . $slot_access . ') }[0..$#{ (' . $slot_access . ') } - 1] '
31              . ': () ]';
32 }
33
34 sub _inline_capture_return_value {
35     my $self = shift;
36     my ($slot_access) = @_;
37
38     return 'my $old = ' . $slot_access . '->[-1];';
39 }
40
41 sub _optimized_set_new_value {
42     my $self = shift;
43     my ($inv, $new, $slot_access) = @_;
44
45     return 'pop @{ (' . $slot_access . ') }';
46 }
47
48 sub _return_value {
49     my $self = shift;
50     my ($slot_access) = @_;
51
52     return '$old';
53 }
54
55 no Moose::Role;
56
57 1;