package Moose::Autobox::Hash;
use Moose::Role 'with';
-our $VERSION = '0.01';
+use Carp qw(croak);
+
+our $VERSION = '0.02';
with 'Moose::Autobox::Ref',
'Moose::Autobox::Indexed';
CORE::delete $hash->{$key};
}
+sub merge {
+ my ($left, $right) = @_;
+ croak "You must pass a hashref as argument to merge"
+ unless ref $right eq 'HASH';
+ return { %$left, %$right };
+}
+
# ::Indexed implementation
sub at {
=item B<delete>
+=item B<merge>
+
+Takes a hashref and returns a new hashref with right precedence
+shallow merging.
+
=back
=head2 Indexed implementation
Stevan Little E<lt>stevan@iinteractive.comE<gt>
+Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
+
=head1 COPYRIGHT AND LICENSE
Copyright 2006 by Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
-=cut
\ No newline at end of file
+=cut
+
use strict;
use warnings;
-use Test::More tests => 55;
+use Test::More tests => 56;
BEGIN {
use_ok('Moose::Autobox');
{ one => 1, two => 2, three => 3 },
'... got the value deleted correctly');
+is_deeply(
+$h->merge({ three => 33, four => 44 }),
+{ one => 1, two => 2, three => 33, four => 44 },
+'... got the hashes merged correctly');
+