1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
use strict;
use warnings;
use Test::More;
#use Data::Dump qw/dump/;
#print dump($left), "\n";
#print dump($merged), "\n";
use Hash::Merge::Simple qw/merge clone_merge dclone_merge/;
my ($left, $right, $result);
SKIP: {
eval "require Clone;" or skip "Clone required for this test";
$left = { foo => { bar => 2 } };
$right = { baz => 4 };
$result = clone_merge( $left, $right );
$left->{foo}{bar} = 3 ;
$left->{foo}{aaa} = 5 ;
is_deeply $left, { foo => { bar => 3, aaa => 5 } };
is_deeply $result, { foo => { bar => 2 }, baz => 4 };
}
SKIP: {
eval "require Storable;" or skip "Storable required for this test";
$left = { foo => { bar => 2 } };
$right = { baz => 4 };
$result = dclone_merge( $left, $right );
$left->{foo}{bar} = 3 ;
$left->{foo}{aaa} = 5 ;
is_deeply $left, { foo => { bar => 3, aaa => 5 } };
is_deeply $result, { foo => { bar => 2 }, baz => 4 };
}
$left = { foo => { bar => 2 } };
$right = { baz => 4 };
$result = merge( $left, $right );
$left->{foo}{bar} = 3 ;
$left->{foo}{aaa} = 5 ;
is_deeply $left, { foo => { bar => 3, aaa => 5 } };
is_deeply $result, { foo => { aaa => 5, bar => 3 }, baz => 4 };
done_testing;
|