3 # Copyright (c) 1995-2000, Raphael Manfredi
5 # You may redistribute only under the same terms as Perl 5, as specified
6 # in the README file that comes with the distribution.
11 require Config; import Config;
12 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
13 print "1..0 # Skip: Storable was not built\n";
20 use Storable qw(dclone);
27 $c->{attribute} = 'attrval';
28 %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
29 @a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
30 $b, \$a, $a, $c, \$c, \%a);
32 print "not " unless defined ($aref = dclone(\@a));
41 print "not " unless $got eq $dumped;
44 package FOO; @ISA = qw(Storable);
48 $self->{key} = \%main::a;
55 print "not " unless defined($r = $foo->dclone);
58 print "not " unless &dump($foo) eq &dump($r);
61 # Ensure refs to "undef" values are properly shared during cloning
63 push @{$$hash{''}}, \$$hash{a};
64 print "not " unless $$hash{''}[0] == \$$hash{a};
67 my $cloned = dclone(dclone($hash));
68 print "not " unless $$cloned{''}[0] == \$$cloned{a};
72 print "not " unless $$cloned{''}[0] == \$$cloned{a};
75 # [ID 20020221.007] SEGV in Storable with empty string scalar object
78 my ($type, $string) = @_;
79 return bless(\$string, $type);
82 my $empty_string_obj = TestString->new('');
83 my $clone = dclone($empty_string_obj);
84 # If still here after the dclone the fix (#17543) worked.
85 print ref $clone eq ref $empty_string_obj &&
86 $$clone eq $$empty_string_obj &&
87 $$clone eq '' ? "ok 10\n" : "not ok 10\n";
90 # Do not fail if Tie::Hash and/or Tie::StdHash is not available
91 if (eval { require Tie::Hash; scalar keys %Tie::StdHash:: }) {
92 tie my %tie, "Tie::StdHash" or die $!;
93 $tie{array} = [1,2,3,4];
94 $tie{hash} = {1,2,3,4};
95 my $clone_array = dclone $tie{array};
96 print "not " unless "@$clone_array" eq "@{$tie{array}}";
98 my $clone_hash = dclone $tie{hash};
99 print "not " unless $clone_hash->{1} eq $tie{hash}{1};
103 ok 11 # skip No Tie::StdHash available
104 ok 12 # skip No Tie::StdHash available