Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/self/root/proc/self/root/usr/share/doc/perl-Moose/t/native_traits/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/proc/self/root/usr/share/doc/perl-Moose/t/native_traits/shallow_clone.t
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;

Hry