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