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 };
26 # ::Indexed implementation
29 my ($hash, $index) = @_;
34 my ($hash, $index, $value) = @_;
35 $hash->{$index} = $value;
39 my ($hash, $key) = @_;
40 CORE::exists $hash->{$key};
45 [ CORE::keys %$hash ];
50 [ CORE::values %$hash ];
55 [ CORE::map { [ $_, $hash->{$_} ] } CORE::keys %$hash ];
59 my ($hash, $keys) = @_;
60 return [ @{$hash}{@$keys} ];
63 sub print { CORE::print %{$_[0]} }
64 sub say { CORE::print %{$_[0]}, "\n" }
74 Moose::Autobox::Hash - the Hash role
80 print { one => 1, two => 2 }->keys->join(', '); # prints 'one, two'
84 This is a role to describes a Hash value.
94 Takes a hashref and returns a new hashref with right precedence
99 Slices a hash but returns the keys and values as a new hashref.
103 =head2 Indexed implementation
135 All complex software has bugs lurking in it, and this module is no
136 exception. If you find a bug please either email me, or add the bug
141 Stevan Little E<lt>stevan@iinteractive.comE<gt>
143 =head1 COPYRIGHT AND LICENSE
145 Copyright 2006-2008 by Infinity Interactive, Inc.
147 L<http://www.iinteractive.com>
149 This library is free software; you can redistribute it and/or modify
150 it under the same terms as Perl itself.