ea96a19326f49a89c976cddf122f32d1001f00fd
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / ImmutableHash.pm
1 package MooseX::AttributeHelpers::MethodProvider::ImmutableHash;
2 use Moose::Role;
3
4 our $VERSION   = '0.03';
5 our $AUTHORITY = 'cpan:STEVAN';
6
7 sub exists : method {
8     my ($attr, $reader, $writer) = @_;    
9     return sub { CORE::exists $reader->($_[0])->{$_[1]} ? 1 : 0 };
10 }   
11
12 sub get : method {
13     my ($attr, $reader, $writer) = @_;    
14     return sub { $reader->($_[0])->{$_[1]} };
15 }
16
17 sub keys : method {
18     my ($attr, $reader, $writer) = @_;
19     return sub { CORE::keys %{$reader->($_[0])} };        
20 }
21      
22 sub values : method {
23     my ($attr, $reader, $writer) = @_;
24     return sub { CORE::values %{$reader->($_[0])} };        
25 }   
26
27 sub 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    
37 sub count : method {
38     my ($attr, $reader, $writer) = @_;
39     return sub { scalar CORE::keys %{$reader->($_[0])} };        
40 }
41
42 sub empty : method {
43     my ($attr, $reader, $writer) = @_;
44     return sub { scalar CORE::keys %{$reader->($_[0])} ? 1 : 0 };        
45 }
46
47 1;
48
49 __END__
50
51 =pod
52
53 =head1 NAME
54
55 MooseX::AttributeHelpers::MethodProvider::ImmutableHash
56   
57 =head1 DESCRIPTION
58
59 This is a role which provides the method generators for 
60 L<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
92 All complex software has bugs lurking in it, and this module is no 
93 exception. If you find a bug please either email me, or add the bug
94 to cpan-RT.
95
96 =head1 AUTHOR
97
98 Stevan Little E<lt>stevan@iinteractive.comE<gt>
99
100 =head1 COPYRIGHT AND LICENSE
101
102 Copyright 2007 by Infinity Interactive, Inc.
103
104 L<http://www.iinteractive.com>
105
106 This library is free software; you can redistribute it and/or modify
107 it under the same terms as Perl itself.
108
109 =cut
110