fix hash accessor generation (with a bit of a hack/:)
[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
8b9641b8 14 )
15 ]
16 },
17 'Moose::Meta::Method::Accessor::Native::Hash::get' => {
18 -excludes => [
19 qw(
20 _generate_method
21 _minimum_arguments
22 _maximum_arguments
23 _inline_check_argument_count
30423145 24 _inline_check_arguments
8b9641b8 25 _inline_process_arguments
30423145 26 _return_value
8b9641b8 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,
a619fc2f 41 $self->_inline_check_lazy($inv, '$type_constraint', '$type_coercion', '$type_message'),
53a4677c 42 # get
43 'if (@_ == 1) {',
30423145 44 # XXX: ugh, this is a hack - we need _return_value from
45 # both ::set and ::get, but we can only have one, so we pick
46 # the one from ::set and munge it to work for the ::get case
47 # this should be fixed in a better way
48 # -doy
49 'my @keys_idx = 0..$#_;',
53a4677c 50 $self->_inline_check_var_is_valid_key('$_[0]'),
51 $self->Moose::Meta::Method::Accessor::Native::Hash::get::_inline_return_value($slot_access),
52 '}',
53 # set
54 'else {',
1e2c801e 55 $self->_inline_writer_core($inv, $slot_access),
53a4677c 56 '}',
57 '}',
58 );
44babf1f 59}
60
1e2c801e 61sub _minimum_arguments { 1 }
62sub _maximum_arguments { 2 }
44babf1f 63
8b9641b8 64no Moose::Role;
44babf1f 65
661;