diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
commit | 5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch) | |
tree | 298c3d2f08bdfe5689998b11892d72a897985be1 /t/native_traits/shallow_clone.t | |
download | Moose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz |
Moose-2.1405HEADMoose-2.1405master
Diffstat (limited to 't/native_traits/shallow_clone.t')
-rw-r--r-- | t/native_traits/shallow_clone.t | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/t/native_traits/shallow_clone.t b/t/native_traits/shallow_clone.t new file mode 100644 index 0000000..6f25a3f --- /dev/null +++ b/t/native_traits/shallow_clone.t @@ -0,0 +1,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; |