Upgrade to Attribute::Handlers 0.70.
[p5sagit/p5-mst-13.2.git] / t / lib / st-dclone.t
CommitLineData
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
15sub 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
28use Storable qw(dclone);
29
30print "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
40print "not " unless defined ($aref = dclone(\@a));
41print "ok 1\n";
42
43$dumped = &dump(\@a);
44print "ok 2\n";
45
46$got = &dump($aref);
47print "ok 3\n";
48
49print "not " unless $got eq $dumped;
50print "ok 4\n";
51
52package FOO; @ISA = qw(Storable);
53
54sub make {
55 my $self = bless {};
56 $self->{key} = \%main::a;
57 return $self;
58};
59
60package main;
61
62$foo = FOO->make;
63print "not " unless defined($r = $foo->dclone);
64print "ok 5\n";
65
66print "not " unless &dump($foo) eq &dump($r);
67print "ok 6\n";
68
69# Ensure refs to "undef" values are properly shared during cloning
70my $hash;
71push @{$$hash{''}}, \$$hash{a};
72print "not " unless $$hash{''}[0] == \$$hash{a};
73print "ok 7\n";
74
75my $cloned = dclone(dclone($hash));
76print "not " unless $$cloned{''}[0] == \$$cloned{a};
77print "ok 8\n";
78
79$$cloned{a} = "blah";
80print "not " unless $$cloned{''}[0] == \$$cloned{a};
81print "ok 9\n";
82