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
|
use strict;
use warnings;
use Test::More;
use Scalar::Util qw(refaddr);
{
package Foo;
use Moose;
has 'array' => (
traits => ['Array'],
is => 'ro',
handles => { array_clone => 'shallow_clone' },
);
has 'hash' => (
traits => ['Hash'],
is => 'ro',
handles => { hash_clone => 'shallow_clone' },
);
no Moose;
}
my $array = [ 1, 2, 3 ];
my $hash = { a => 1, b => 2 };
my $obj = Foo->new({
array => $array,
hash => $hash,
});
my $array_clone = $obj->array_clone;
my $hash_clone = $obj->hash_clone;
isnt(refaddr($array), refaddr($array_clone), "array clone refers to new copy");
is_deeply($array_clone, $array, "...but contents are the same");
isnt(refaddr($hash), refaddr($hash_clone), "hash clone refers to new copy");
is_deeply($hash_clone, $hash, "...but contents are the same");
done_testing;
|