4 if( $ENV{PERL_CORE} ) {
11 unless ( eval { require Storable; 1 } ){
12 print "1..0 # Skip -- Storable is not available\n";
21 use Storable qw/dclone nfreeze thaw/;
27 print ( ( $_[0] ? "" : "not " ), "ok - $_[1]" );
31 print ( ( ( $_[0] eq $_[1] ) ? "" : "not "), "ok - $_[2]" );
35 ok( eval { $_[0]->isa($_[1]) }, "the object isa $_[1]");
38 tie my %hash, "Tie::RefHash";
40 my $key = { foo => 1 };
41 $hash{$key} = "value";
42 $hash{non_ref} = "other";
44 foreach my $clone ( \%hash, dclone(\%hash), thaw(nfreeze(\%hash)) ){
46 ok( tied(%$clone), "copy is tied");
47 isa_ok( tied(%$clone), "Tie::RefHash" );
49 my @keys = keys %$clone;
50 is( scalar(@keys), 2, "one key in clone");
51 my $key = ref($keys[0]) ? shift @keys : pop @keys;
54 ok( ref($key), "key is a ref after clone" );
55 is( $key->{foo}, 1, "key serialized ok");
57 is( $clone->{$key}, "value", "and is still pointing at the same value" );
59 ok( !ref($reg), "regular key is non ref" );
60 is( $clone->{$reg}, "other", "and is also a valid key" );