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.
12 @INC = ('.', '../lib', '../ext/Storable/t');
16 require Config; import Config;
17 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
18 print "1..0 # Skip: Storable was not built\n";
25 use Storable qw(dclone);
32 $c->{attribute} = 'attrval';
33 %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
34 @a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
35 $b, \$a, $a, $c, \$c, \%a);
37 print "not " unless defined ($aref = dclone(\@a));
46 print "not " unless $got eq $dumped;
49 package FOO; @ISA = qw(Storable);
53 $self->{key} = \%main::a;
60 print "not " unless defined($r = $foo->dclone);
63 print "not " unless &dump($foo) eq &dump($r);
66 # Ensure refs to "undef" values are properly shared during cloning
68 push @{$$hash{''}}, \$$hash{a};
69 print "not " unless $$hash{''}[0] == \$$hash{a};
72 my $cloned = dclone(dclone($hash));
73 print "not " unless $$cloned{''}[0] == \$$cloned{a};
77 print "not " unless $$cloned{''}[0] == \$$cloned{a};
80 # [ID 20020221.007] SEGV in Storable with empty string scalar object
83 my ($type, $string) = @_;
84 return bless(\$string, $type);
87 my $empty_string_obj = TestString->new('');
88 my $clone = dclone($empty_string_obj);
89 # If still here after the dclone the fix (#17543) worked.
90 print ref $clone eq ref $empty_string_obj &&
91 $$clone eq $$empty_string_obj &&
92 $$clone eq '' ? "ok 10\n" : "not ok 10\n";
95 # Do not fail if Tie::Hash and/or Tie::StdHash is not available
96 if (eval { require Tie::Hash; scalar keys %Tie::StdHash:: }) {
97 tie my %tie, "Tie::StdHash" or die $!;
98 $tie{array} = [1,2,3,4];
99 $tie{hash} = {1,2,3,4};
100 my $clone_array = dclone $tie{array};
101 print "not " unless "@$clone_array" eq "@{$tie{array}}";
103 my $clone_hash = dclone $tie{hash};
104 print "not " unless $clone_hash->{1} eq $tie{hash}{1};
108 ok 11 # skip No Tie::StdHash available
109 ok 12 # skip No Tie::StdHash available