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} ];
67 sub print { CORE::print %{$_[0]} }
68 sub say { CORE::print %{$_[0]}, "\n" }
78 Moose::Autobox::Hash - the Hash role
84 print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two'
88 This is a role to describes a Hash value.
98 Takes a hashref and returns a new hashref with right precedence
103 Slices a hash but returns the keys and values as a new hashref.
109 =head2 Indexed implementation
141 All complex software has bugs lurking in it, and this module is no
142 exception. If you find a bug please either email me, or add the bug
147 Stevan Little E<lt>stevan@iinteractive.comE<gt>
149 =head1 COPYRIGHT AND LICENSE
151 Copyright 2006-2008 by Infinity Interactive, Inc.
153 L<http://www.iinteractive.com>
155 This library is free software; you can redistribute it and/or modify
156 it under the same terms as Perl itself.