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