7 require Config; import Config;
8 keys %Config; # Silence warning
9 if ($Config{extensions} !~ /\bList\/Util\b/) {
10 print "1..0 # Skip: List::Util was not built\n";
17 use Test::More (grep { /weaken/ } @Scalar::Util::EXPORT_FAIL)
18 ? (skip_all => 'weaken requires XS version')
23 Devel::Peek->import('Dump');
29 Scalar::Util->import(qw(weaken isweak));
36 # Case 1: two references, one is weakened, the other is then undef'ed.
47 ok( ref($y) and ref($z));
53 ok( ref($y) and ref($z));
59 ok( not (defined($y) and defined($z)) );
65 ok( not (defined($y) and defined($z)) );
72 # Case 2: one reference, which is weakened
90 print "# EXITBLOCK\n";
94 # Case 3: a circular structure
99 my $y = bless {}, Dest;
110 print "# VALS: HASH ",$y," SELF ",\$y->{Self}," Y ",\$y,
111 " FLAG: ",\$y->{Flag},"\n";
114 print "# OUT $flag\n";
124 # Case 4: a more complicated circular structure
129 my $y = bless {}, Dest;
130 my $x = bless {}, Dest;
140 # Case 5: deleting a weakref before the other one
161 # Case 6: test isweakref
174 weaken($x->{Y} = \$a);
176 ok(!isweak($x->{Z}));
179 # Case 7: test weaken on a read only ref
183 # Doesn't work for older perls, see bug [perl #24506]
184 skip("Test does not work with perl < 5.8.3", 5) if $] < 5.008003;
186 $a = eval '\"hello"';
187 ok(ref($a)) or print "# didn't get a ref from eval\n";
191 ok($@ eq "") or print "# died with $@\n";
193 ok($$b eq "hello") or print "# b is '$$b'\n";
195 ok(not $b) or print "# b didn't go away\n";