Commit | Line | Data |
7a6a85bf |
1 | #!./perl |
7a6a85bf |
2 | # |
3 | # Copyright (c) 1995-2000, Raphael Manfredi |
4 | # |
9e21b3d0 |
5 | # You may redistribute only under the same terms as Perl 5, as specified |
6 | # in the README file that comes with the distribution. |
7a6a85bf |
7 | # |
7a6a85bf |
8 | |
9 | sub BEGIN { |
0c384302 |
10 | if ($ENV{PERL_CORE}){ |
11 | chdir('t') if -d 't'; |
7dadce44 |
12 | @INC = ('.', '../lib', '../ext/Storable/t'); |
372cb964 |
13 | } else { |
14 | unshift @INC, 't'; |
0c384302 |
15 | } |
9f233367 |
16 | require Config; import Config; |
0c384302 |
17 | if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) { |
9f233367 |
18 | print "1..0 # Skip: Storable was not built\n"; |
19 | exit 0; |
20 | } |
372cb964 |
21 | require 'st-dump.pl'; |
7a6a85bf |
22 | } |
23 | |
24 | |
25 | use Storable qw(dclone); |
26 | |
14bff8b8 |
27 | print "1..10\n"; |
7a6a85bf |
28 | |
29 | $a = 'toto'; |
30 | $b = \$a; |
31 | $c = bless {}, CLASS; |
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); |
36 | |
37 | print "not " unless defined ($aref = dclone(\@a)); |
38 | print "ok 1\n"; |
39 | |
40 | $dumped = &dump(\@a); |
41 | print "ok 2\n"; |
42 | |
43 | $got = &dump($aref); |
44 | print "ok 3\n"; |
45 | |
46 | print "not " unless $got eq $dumped; |
47 | print "ok 4\n"; |
48 | |
49 | package FOO; @ISA = qw(Storable); |
50 | |
51 | sub make { |
52 | my $self = bless {}; |
53 | $self->{key} = \%main::a; |
54 | return $self; |
55 | }; |
56 | |
57 | package main; |
58 | |
59 | $foo = FOO->make; |
60 | print "not " unless defined($r = $foo->dclone); |
61 | print "ok 5\n"; |
62 | |
63 | print "not " unless &dump($foo) eq &dump($r); |
64 | print "ok 6\n"; |
65 | |
66 | # Ensure refs to "undef" values are properly shared during cloning |
67 | my $hash; |
68 | push @{$$hash{''}}, \$$hash{a}; |
69 | print "not " unless $$hash{''}[0] == \$$hash{a}; |
70 | print "ok 7\n"; |
71 | |
72 | my $cloned = dclone(dclone($hash)); |
73 | print "not " unless $$cloned{''}[0] == \$$cloned{a}; |
74 | print "ok 8\n"; |
75 | |
76 | $$cloned{a} = "blah"; |
77 | print "not " unless $$cloned{''}[0] == \$$cloned{a}; |
78 | print "ok 9\n"; |
79 | |
14bff8b8 |
80 | # [ID 20020221.007] SEGV in Storable with empty string scalar object |
81 | package TestString; |
82 | sub new { |
83 | my ($type, $string) = @_; |
84 | return bless(\$string, $type); |
85 | } |
86 | package main; |
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"; |