foo
[gitmo/Moose-Autobox.git] / lib / Moose / Autobox / Hash.pm
1 package Moose::Autobox::Hash;
2 use Moose::Role 'with';
3
4 our $VERSION = '0.01';
5
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
15
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
26 sub exists { 
27     my ($hash, $key) = @_;
28     CORE::exists $hash->{$key}; 
29 }
30
31 sub keys { 
32     my ($hash) = @_;
33     [ CORE::keys %$hash ];
34 }
35
36 sub values { 
37     my ($hash) = @_;    
38     [ CORE::values %$hash ]; 
39 }
40
41 sub kv {
42     my ($hash) = @_;    
43     [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ];    
44 }
45
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;
59   use autobox;
60   
61   print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two'
62
63 =head1 DESCRIPTION
64
65 This is a role to describes a Hash value. 
66
67 =head1 METHODS
68
69 =over 4
70
71 =item B<meta>
72
73 =item B<delete>
74
75 =back
76
77 =head2 Moose::Autobox::Indexed implementation
78
79 =over 4
80
81 =item B<at>
82
83 =item B<put>
84
85 =item B<exists>
86
87 =item B<keys>
88
89 =item B<values>
90
91 =item B<kv>
92
93 =back
94
95 =head1 BUGS
96
97 All complex software has bugs lurking in it, and this module is no 
98 exception. If you find a bug please either email me, or add the bug
99 to cpan-RT.
100
101 =head1 AUTHOR
102
103 Stevan Little E<lt>stevan@iinteractive.comE<gt>
104
105 =head1 COPYRIGHT AND LICENSE
106
107 Copyright 2006 by Infinity Interactive, Inc.
108
109 L<http://www.iinteractive.com>
110
111 This library is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself.
113
114 =cut