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