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