Commit | Line | Data |
5f654d8e |
1 | package Moose::Autobox::Hash; |
2 | use Moose::Role 'with'; |
3 | |
4 | our $VERSION = '0.01'; |
5 | |
6cf5bcf2 |
6 | with 'Moose::Autobox::Ref', |
7 | 'Moose::Autobox::Indexed'; |
8 | |
9 | sub delete { |
10 | my ($hash, $key) = @_; |
11 | CORE::delete $hash->{$key}; |
12 | } |
13 | |
14 | # ::Indexed implementation |
5f654d8e |
15 | |
31d40d73 |
16 | sub at { |
17 | my ($hash, $index) = @_; |
18 | $hash->{$index}; |
19 | } |
20 | |
21 | sub put { |
22 | my ($hash, $index, $value) = @_; |
23 | $hash->{$index} = $value; |
24 | } |
25 | |
5f654d8e |
26 | sub exists { |
27 | my ($hash, $key) = @_; |
28 | CORE::exists $hash->{$key}; |
29 | } |
e6bb88b0 |
30 | |
5f654d8e |
31 | sub keys { |
32 | my ($hash) = @_; |
e6bb88b0 |
33 | [ CORE::keys %$hash ]; |
5f654d8e |
34 | } |
35 | |
36 | sub values { |
37 | my ($hash) = @_; |
e6bb88b0 |
38 | [ CORE::values %$hash ]; |
39 | } |
40 | |
41 | sub kv { |
42 | my ($hash) = @_; |
43 | [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ]; |
5f654d8e |
44 | } |
45 | |
31d40d73 |
46 | 1; |
47 | |
48 | __END__ |
49 | |
50 | =pod |
51 | |
52 | =head1 NAME |
53 | |
54 | Moose::Autobox::Hash - the Hash role |
55 | |
56 | =head1 SYNOPOSIS |
57 | |
58 | use Moose::Autobox; |
31d40d73 |
59 | |
8937074a |
60 | print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two' |
31d40d73 |
61 | |
62 | =head1 DESCRIPTION |
63 | |
8937074a |
64 | This is a role to describes a Hash value. |
65 | |
260cc81f |
66 | =head1 METHODS |
67 | |
68 | =over 4 |
69 | |
260cc81f |
70 | =item B<delete> |
71 | |
72 | =back |
73 | |
5272f13f |
74 | =head2 Indexed implementation |
260cc81f |
75 | |
76 | =over 4 |
77 | |
78 | =item B<at> |
79 | |
80 | =item B<put> |
81 | |
82 | =item B<exists> |
83 | |
84 | =item B<keys> |
85 | |
86 | =item B<values> |
87 | |
88 | =item B<kv> |
89 | |
90 | =back |
91 | |
5272f13f |
92 | =over 4 |
93 | |
94 | =item B<meta> |
95 | |
96 | =back |
97 | |
31d40d73 |
98 | =head1 BUGS |
99 | |
100 | All complex software has bugs lurking in it, and this module is no |
101 | exception. If you find a bug please either email me, or add the bug |
102 | to cpan-RT. |
103 | |
104 | =head1 AUTHOR |
105 | |
106 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
107 | |
108 | =head1 COPYRIGHT AND LICENSE |
109 | |
110 | Copyright 2006 by Infinity Interactive, Inc. |
111 | |
112 | L<http://www.iinteractive.com> |
113 | |
114 | This library is free software; you can redistribute it and/or modify |
115 | it under the same terms as Perl itself. |
116 | |
117 | =cut |