1 package Moose::Autobox::Hash;
2 use Moose::Role 'with';
6 with 'Moose::Autobox::Ref',
7 'Moose::Autobox::Indexed';
10 my ($hash, $key) = @_;
11 CORE::delete $hash->{$key};
15 my ($left, $right) = @_;
16 Carp::confess "You must pass a hashref as argument to merge"
17 unless ref $right eq 'HASH';
18 return { %$left, %$right };
22 my ($hash, $keys) = @_;
23 return { map { $_ => $hash->{$_} } @$keys };
30 # ::Indexed implementation
33 my ($hash, $index) = @_;
38 my ($hash, $index, $value) = @_;
39 $hash->{$index} = $value;
43 my ($hash, $key) = @_;
44 CORE::exists $hash->{$key};
49 [ CORE::keys %$hash ];
54 [ CORE::values %$hash ];
59 [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ];
63 my ($hash, $keys) = @_;
64 return [ @{$hash}{@$keys} ];
68 my ($hash, $sub) = @_;
69 for my $key (CORE::keys %$hash) {
70 $sub->($key, $hash->{$key});
75 my ($hash, $sub) = @_;
76 $sub->($_) for CORE::keys %$hash;
80 my ($hash, $sub) = @_;
81 $sub->($_) for CORE::values %$hash;
85 my ($hash, $n, $sub) = @_;
86 my @keys = CORE::keys %$hash;
87 my $it = List::MoreUtils::natatime($n, @keys);
89 while (my @vals = $it->()) {
90 $sub->(@$hash{ @vals });
99 sub print { CORE::print %{$_[0]} }
100 sub say { CORE::print %{$_[0]}, "\n" }
110 Moose::Autobox::Hash - the Hash role
116 print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two'
120 This is a role to describes a Hash value.
130 Takes a hashref and returns a new hashref with right precedence
135 Slices a hash but returns the keys and values as a new hashref.
141 =head2 Indexed implementation
165 =item B<each_n_values>
181 All complex software has bugs lurking in it, and this module is no
182 exception. If you find a bug please either email me, or add the bug
187 Stevan Little E<lt>stevan@iinteractive.comE<gt>
189 =head1 COPYRIGHT AND LICENSE
191 Copyright 2006-2008 by Infinity Interactive, Inc.
193 L<http://www.iinteractive.com>
195 This library is free software; you can redistribute it and/or modify
196 it under the same terms as Perl itself.