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.
21 require Config; import Config;
22 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
23 print "1..0 # Skip: Storable was not built\n";
26 require 'lib/st-dump.pl';
30 use Storable qw(dclone);
37 $c->{attribute} = 'attrval';
38 %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
39 @a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
40 $b, \$a, $a, $c, \$c, \%a);
42 print "not " unless defined ($aref = dclone(\@a));
51 print "not " unless $got eq $dumped;
54 package FOO; @ISA = qw(Storable);
58 $self->{key} = \%main::a;
65 print "not " unless defined($r = $foo->dclone);
68 print "not " unless &dump($foo) eq &dump($r);
71 # Ensure refs to "undef" values are properly shared during cloning
73 push @{$$hash{''}}, \$$hash{a};
74 print "not " unless $$hash{''}[0] == \$$hash{a};
77 my $cloned = dclone(dclone($hash));
78 print "not " unless $$cloned{''}[0] == \$$cloned{a};
82 print "not " unless $$cloned{''}[0] == \$$cloned{a};
85 # [ID 20020221.007] SEGV in Storable with empty string scalar object
88 my ($type, $string) = @_;
89 return bless(\$string, $type);
92 my $empty_string_obj = TestString->new('');
93 my $clone = dclone($empty_string_obj);
94 # If still here after the dclone the fix (#17543) worked.
95 print ref $clone eq ref $empty_string_obj &&
96 $$clone eq $$empty_string_obj &&
97 $$clone eq '' ? "ok 10\n" : "not ok 10\n";