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