refactor constructor inlining to reuse attribute code
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / accessor.pm
CommitLineData
a7821be5 1package Moose::Meta::Method::Accessor::Native::Array::accessor;
2
3use strict;
4use warnings;
5
245478d5 6our $VERSION = '1.19';
a7821be5 7$VERSION = eval $VERSION;
8our $AUTHORITY = 'cpan:STEVAN';
9
8b9641b8 10use Moose::Role;
11
12with '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 };
a7821be5 31
32sub _generate_method {
33 my $self = shift;
34
53a4677c 35 my $inv = '$self';
1e2c801e 36 my $slot_access = $self->_get_value($inv);
a7821be5 37
53a4677c 38 return (
39 'sub {',
53a4677c 40 'my ' . $inv . ' = shift;',
41 $self->_inline_curried_arguments,
ec86bdff 42 $self->_inline_check_lazy($inv, '$type_constraint', '$type_constraint_obj'),
53a4677c 43 # get
44 'if (@_ == 1) {',
45 $self->_inline_check_var_is_valid_index('$_[0]'),
46 $self->Moose::Meta::Method::Accessor::Native::Array::get::_inline_return_value($slot_access),
47 '}',
48 # set
49 'else {',
1e2c801e 50 $self->_inline_writer_core($inv, $slot_access),
53a4677c 51 '}',
52 '}',
53 );
a7821be5 54}
55
1e2c801e 56sub _minimum_arguments { 1 }
57sub _maximum_arguments { 2 }
a7821be5 58
8b9641b8 59no Moose::Role;
a7821be5 60
611;