Commit | Line | Data |
7a6a85bf |
1 | #!./perl |
2 | |
9e21b3d0 |
3 | # $Id: dclone.t,v 1.0 2000/09/01 19:40:41 ram Exp $ |
7a6a85bf |
4 | # |
5 | # Copyright (c) 1995-2000, Raphael Manfredi |
6 | # |
9e21b3d0 |
7 | # You may redistribute only under the same terms as Perl 5, as specified |
8 | # in the README file that comes with the distribution. |
7a6a85bf |
9 | # |
10 | # $Log: dclone.t,v $ |
9e21b3d0 |
11 | # Revision 1.0 2000/09/01 19:40:41 ram |
12 | # Baseline for first official release. |
7a6a85bf |
13 | # |
14 | |
15 | sub BEGIN { |
16 | chdir('t') if -d 't'; |
20822f61 |
17 | @INC = '.'; |
18 | push @INC, '../lib'; |
9f233367 |
19 | require Config; import Config; |
20 | if ($Config{'extensions'} !~ /\bStorable\b/) { |
21 | print "1..0 # Skip: Storable was not built\n"; |
22 | exit 0; |
23 | } |
7a6a85bf |
24 | require 'lib/st-dump.pl'; |
25 | } |
26 | |
27 | |
28 | use Storable qw(dclone); |
29 | |
30 | print "1..9\n"; |
31 | |
32 | $a = 'toto'; |
33 | $b = \$a; |
34 | $c = bless {}, CLASS; |
35 | $c->{attribute} = 'attrval'; |
36 | %a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c); |
37 | @a = ('first', undef, 3, -4, -3.14159, 456, 4.5, |
38 | $b, \$a, $a, $c, \$c, \%a); |
39 | |
40 | print "not " unless defined ($aref = dclone(\@a)); |
41 | print "ok 1\n"; |
42 | |
43 | $dumped = &dump(\@a); |
44 | print "ok 2\n"; |
45 | |
46 | $got = &dump($aref); |
47 | print "ok 3\n"; |
48 | |
49 | print "not " unless $got eq $dumped; |
50 | print "ok 4\n"; |
51 | |
52 | package FOO; @ISA = qw(Storable); |
53 | |
54 | sub make { |
55 | my $self = bless {}; |
56 | $self->{key} = \%main::a; |
57 | return $self; |
58 | }; |
59 | |
60 | package main; |
61 | |
62 | $foo = FOO->make; |
63 | print "not " unless defined($r = $foo->dclone); |
64 | print "ok 5\n"; |
65 | |
66 | print "not " unless &dump($foo) eq &dump($r); |
67 | print "ok 6\n"; |
68 | |
69 | # Ensure refs to "undef" values are properly shared during cloning |
70 | my $hash; |
71 | push @{$$hash{''}}, \$$hash{a}; |
72 | print "not " unless $$hash{''}[0] == \$$hash{a}; |
73 | print "ok 7\n"; |
74 | |
75 | my $cloned = dclone(dclone($hash)); |
76 | print "not " unless $$cloned{''}[0] == \$$cloned{a}; |
77 | print "ok 8\n"; |
78 | |
79 | $$cloned{a} = "blah"; |
80 | print "not " unless $$cloned{''}[0] == \$$cloned{a}; |
81 | print "ok 9\n"; |
82 | |