1 package Moose::Autobox::Hash;
2 use Moose::Role 'with';
8 with 'Moose::Autobox::Ref',
9 'Moose::Autobox::Indexed';
12 my ($hash, $key) = @_;
13 CORE::delete $hash->{$key};
17 my ($left, $right) = @_;
18 croak "You must pass a hashref as argument to merge"
19 unless ref $right eq 'HASH';
20 return { %$left, %$right };
24 my ($hash, $keys) = @_;
25 return { map { $_ => $hash->{$_} } @$keys };
28 # ::Indexed implementation
31 my ($hash, $index) = @_;
36 my ($hash, $index, $value) = @_;
37 $hash->{$index} = $value;
41 my ($hash, $key) = @_;
42 CORE::exists $hash->{$key};
47 [ CORE::keys %$hash ];
52 [ CORE::values %$hash ];
57 [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ];
61 my ($hash, $keys) = @_;
62 return [ @{$hash}{@$keys} ];
65 sub print { CORE::print %{$_[0]} }
66 sub say { CORE::print %{$_[0]}, "\n" }
76 Moose::Autobox::Hash - the Hash role
82 print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two'
86 This is a role to describes a Hash value.
96 Takes a hashref and returns a new hashref with right precedence
101 Slices a hash but returns the keys and values as a new hashref.
105 =head2 Indexed implementation
137 All complex software has bugs lurking in it, and this module is no
138 exception. If you find a bug please either email me, or add the bug
143 Stevan Little E<lt>stevan@iinteractive.comE<gt>
145 =head1 COPYRIGHT AND LICENSE
147 Copyright 2006-2008 by Infinity Interactive, Inc.
149 L<http://www.iinteractive.com>
151 This library is free software; you can redistribute it and/or modify
152 it under the same terms as Perl itself.