3 # $Id: dclone.t,v 1.0 2000/09/01 19:40:41 ram Exp $
5 # Copyright (c) 1995-2000, Raphael Manfredi
7 # You may redistribute only under the same terms as Perl 5, as specified
8 # in the README file that comes with the distribution.
11 # Revision 1.0 2000/09/01 19:40:41 ram
12 # Baseline for first official release.
18 @INC = ('.', '../lib', '../ext/Storable/t');
22 require Config; import Config;
23 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
24 print "1..0 # Skip: Storable was not built\n";
31 use Storable qw(dclone);
38 $c->{attribute} = 'attrval';
39 %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
40 @a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
41 $b, \$a, $a, $c, \$c, \%a);
43 print "not " unless defined ($aref = dclone(\@a));
52 print "not " unless $got eq $dumped;
55 package FOO; @ISA = qw(Storable);
59 $self->{key} = \%main::a;
66 print "not " unless defined($r = $foo->dclone);
69 print "not " unless &dump($foo) eq &dump($r);
72 # Ensure refs to "undef" values are properly shared during cloning
74 push @{$$hash{''}}, \$$hash{a};
75 print "not " unless $$hash{''}[0] == \$$hash{a};
78 my $cloned = dclone(dclone($hash));
79 print "not " unless $$cloned{''}[0] == \$$cloned{a};
83 print "not " unless $$cloned{''}[0] == \$$cloned{a};
86 # [ID 20020221.007] SEGV in Storable with empty string scalar object
89 my ($type, $string) = @_;
90 return bless(\$string, $type);
93 my $empty_string_obj = TestString->new('');
94 my $clone = dclone($empty_string_obj);
95 # If still here after the dclone the fix (#17543) worked.
96 print ref $clone eq ref $empty_string_obj &&
97 $$clone eq $$empty_string_obj &&
98 $$clone eq '' ? "ok 10\n" : "not ok 10\n";