0.06
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / Hash.pm
CommitLineData
65a43f48 1package MooseX::AttributeHelpers::MethodProvider::Hash;
2use Moose::Role;
3
9a976497 4our $VERSION = '0.03';
457dc4fb 5our $AUTHORITY = 'cpan:STEVAN';
6
9a976497 7with 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash';
65a43f48 8
9sub set : method {
457dc4fb 10 my ($attr, $reader, $writer) = @_;
9a976497 11 if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
12 my $container_type_constraint = $attr->type_constraint->type_parameter;
65a43f48 13 return sub {
14 ($container_type_constraint->check($_[2]))
15 || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
457dc4fb 16 $reader->($_[0])->{$_[1]} = $_[2]
65a43f48 17 };
18 }
19 else {
457dc4fb 20 return sub { $reader->($_[0])->{$_[1]} = $_[2] };
65a43f48 21 }
22}
23
8cf40f80 24sub clear : method {
25 my ($attr, $reader, $writer) = @_;
26 return sub { %{$reader->($_[0])} = () };
27}
28
65a43f48 29sub delete : method {
457dc4fb 30 my ($attr, $reader, $writer) = @_;
9a976497 31 return sub { CORE::delete $reader->($_[0])->{$_[1]} };
65a43f48 32}
33
341;
35
5431dff2 36__END__
37
38=pod
39
40=head1 NAME
41
42MooseX::AttributeHelpers::MethodProvider::Hash
43
44=head1 DESCRIPTION
45
46This is a role which provides the method generators for
47L<MooseX::AttributeHelpers::Collection::Hash>.
48
9a976497 49This role is composed from the
50L<MooseX::AttributeHelpers::Collection::ImmutableHash> role.
51
5431dff2 52=head1 METHODS
53
54=over 4
55
56=item B<meta>
57
58=back
59
60=head1 PROVIDED METHODS
61
62=over 4
63
64=item B<count>
65
66=item B<delete>
67
68=item B<empty>
69
8cf40f80 70=item B<clear>
71
5431dff2 72=item B<exists>
73
74=item B<get>
75
76=item B<keys>
77
78=item B<set>
79
80=item B<values>
81
9a976497 82=item B<kv>
83
5431dff2 84=back
85
86=head1 BUGS
87
88All complex software has bugs lurking in it, and this module is no
89exception. If you find a bug please either email me, or add the bug
90to cpan-RT.
91
92=head1 AUTHOR
93
94Stevan Little E<lt>stevan@iinteractive.comE<gt>
95
96=head1 COPYRIGHT AND LICENSE
97
98Copyright 2007 by Infinity Interactive, Inc.
99
100L<http://www.iinteractive.com>
101
102This library is free software; you can redistribute it and/or modify
103it under the same terms as Perl itself.
104
105=cut
106