Commit | Line | Data |
9a976497 |
1 | package MooseX::AttributeHelpers::MethodProvider::ImmutableHash; |
2 | use Moose::Role; |
3 | |
9e2db1c2 |
4 | our $VERSION = '0.17'; |
38430345 |
5 | $VERSION = eval $VERSION; |
9a976497 |
6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | |
8 | sub exists : method { |
56803bef |
9 | my ($attr, $reader, $writer) = @_; |
9a976497 |
10 | return sub { CORE::exists $reader->($_[0])->{$_[1]} ? 1 : 0 }; |
56803bef |
11 | } |
9a976497 |
12 | |
c0dcad02 |
13 | sub defined : method { |
56803bef |
14 | my ($attr, $reader, $writer) = @_; |
c0dcad02 |
15 | return sub { CORE::defined $reader->($_[0])->{$_[1]} ? 1 : 0 }; |
56803bef |
16 | } |
c0dcad02 |
17 | |
9a976497 |
18 | sub 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 | |
30 | sub keys : method { |
31 | my ($attr, $reader, $writer) = @_; |
56803bef |
32 | return sub { CORE::keys %{$reader->($_[0])} }; |
9a976497 |
33 | } |
56803bef |
34 | |
9a976497 |
35 | sub values : method { |
36 | my ($attr, $reader, $writer) = @_; |
56803bef |
37 | return sub { CORE::values %{$reader->($_[0])} }; |
38 | } |
9a976497 |
39 | |
40 | sub 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 |
50 | sub count : method { |
51 | my ($attr, $reader, $writer) = @_; |
56803bef |
52 | return sub { scalar CORE::keys %{$reader->($_[0])} }; |
9a976497 |
53 | } |
54 | |
55 | sub empty : method { |
56 | my ($attr, $reader, $writer) = @_; |
56803bef |
57 | return sub { scalar CORE::keys %{$reader->($_[0])} ? 1 : 0 }; |
9a976497 |
58 | } |
59 | |
60 | 1; |
61 | |
62 | __END__ |
63 | |
64 | =pod |
65 | |
66 | =head1 NAME |
67 | |
68 | MooseX::AttributeHelpers::MethodProvider::ImmutableHash |
56803bef |
69 | |
9a976497 |
70 | =head1 DESCRIPTION |
71 | |
56803bef |
72 | This is a role which provides the method generators for |
9a976497 |
73 | L<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 | |
89 | =item B<empty> |
90 | |
91 | =item B<exists> |
92 | |
f82de33d |
93 | =item B<defined> |
94 | |
9a976497 |
95 | =item B<get> |
96 | |
97 | =item B<keys> |
98 | |
99 | =item B<values> |
100 | |
101 | =item B<kv> |
102 | |
103 | =back |
104 | |
105 | =head1 BUGS |
106 | |
56803bef |
107 | All complex software has bugs lurking in it, and this module is no |
9a976497 |
108 | exception. If you find a bug please either email me, or add the bug |
109 | to cpan-RT. |
110 | |
111 | =head1 AUTHOR |
112 | |
113 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
114 | |
115 | =head1 COPYRIGHT AND LICENSE |
116 | |
99c62fb8 |
117 | Copyright 2007-2008 by Infinity Interactive, Inc. |
9a976497 |
118 | |
119 | L<http://www.iinteractive.com> |
120 | |
121 | This library is free software; you can redistribute it and/or modify |
122 | it under the same terms as Perl itself. |
123 | |
124 | =cut |
125 | |