5d3fdab67089a8a55bfe3191c94be220d075a2b1
[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 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::set' => {
13     -excludes => [
14         qw( _generate_method
15             _minimum_arguments
16             _maximum_arguments
17             _inline_process_arguments
18             _inline_check_arguments
19             _return_value)
20     ]
21     },
22     'Moose::Meta::Method::Accessor::Native::Array::get' => {
23     -excludes => [
24         qw(
25             _generate_method
26             _minimum_arguments
27             _maximum_arguments
28             )
29     ]
30     };
31
32 sub _generate_method {
33     my $self = shift;
34
35     my $inv         = '$self';
36     my $slot_access = $self->_get_value($inv);
37
38     return (
39         'sub {',
40             $self->_inline_pre_body(@_),
41             'my ' . $inv . ' = shift;',
42             $self->_inline_curried_arguments,
43             $self->_inline_check_lazy($inv),
44             # get
45             'if (@_ == 1) {',
46                 $self->_inline_check_var_is_valid_index('$_[0]'),
47                 $self->Moose::Meta::Method::Accessor::Native::Array::get::_inline_return_value($slot_access),
48             '}',
49             # set
50             'else {',
51                 $self->_inline_writer_core($inv, $slot_access),
52                 $self->_inline_post_body(@_),
53             '}',
54         '}',
55     );
56 }
57
58 sub _minimum_arguments { 1 }
59 sub _maximum_arguments { 2 }
60
61 no Moose::Role;
62
63 1;