stop closing over the type constraint object
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / accessor.pm
1 package Moose::Meta::Method::Accessor::Native::Array::accessor;
2
3 use strict;
4 use warnings;
5
6 use Moose::Role;
7
8 with 'Moose::Meta::Method::Accessor::Native::Array::set' => {
9     -excludes => [
10         qw( _generate_method
11             _minimum_arguments
12             _maximum_arguments
13             _inline_process_arguments
14             _inline_check_arguments
15             _return_value)
16     ]
17     },
18     'Moose::Meta::Method::Accessor::Native::Array::get' => {
19     -excludes => [
20         qw(
21             _generate_method
22             _minimum_arguments
23             _maximum_arguments
24             )
25     ]
26     };
27
28 sub _generate_method {
29     my $self = shift;
30
31     my $inv         = '$self';
32     my $slot_access = $self->_get_value($inv);
33
34     return (
35         'sub {',
36             'my ' . $inv . ' = shift;',
37             $self->_inline_curried_arguments,
38             $self->_inline_check_lazy($inv, '$type_constraint', '$type_coercion', '$type_message'),
39             # get
40             'if (@_ == 1) {',
41                 $self->_inline_check_var_is_valid_index('$_[0]'),
42                 $self->Moose::Meta::Method::Accessor::Native::Array::get::_inline_return_value($slot_access),
43             '}',
44             # set
45             'else {',
46                 $self->_inline_writer_core($inv, $slot_access),
47             '}',
48         '}',
49     );
50 }
51
52 sub _minimum_arguments { 1 }
53 sub _maximum_arguments { 2 }
54
55 no Moose::Role;
56
57 1;