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