9 keys %Config; # Silence warning
10 if ($Config{extensions} !~ /\bList\/Util\b/) {
11 print "1..0 # Skip: List::Util was not built\n";
18 use Test::More ((grep { /weaken/ } @Scalar::Util::EXPORT_FAIL) and !$ENV{PERL_CORE})
19 ? (skip_all => 'weaken requires XS version')
24 Devel::Peek->import('Dump');
30 Scalar::Util->import(qw(weaken isweak));
37 # Case 1: two references, one is weakened, the other is then undef'ed.
48 ok( ref($y) and ref($z));
54 ok( ref($y) and ref($z));
60 ok( not (defined($y) and defined($z)) );
66 ok( not (defined($y) and defined($z)) );
73 # Case 2: one reference, which is weakened
91 print "# EXITBLOCK\n";
95 # Case 3: a circular structure
100 my $y = bless {}, 'Dest';
111 print "# VALS: HASH ",$y," SELF ",\$y->{Self}," Y ",\$y,
112 " FLAG: ",\$y->{Flag},"\n";
115 print "# OUT $flag\n";
125 # Case 4: a more complicated circular structure
130 my $y = bless {}, 'Dest';
131 my $x = bless {}, 'Dest';
141 # Case 5: deleting a weakref before the other one
163 # Case 6: test isweakref
176 weaken($x->{Y} = \$a);
178 ok(!isweak($x->{Z}));
181 # Case 7: test weaken on a read only ref
185 # Doesn't work for older perls, see bug [perl #24506]
186 skip("Test does not work with perl < 5.8.3", 5) if $] < 5.008003;
188 # in a MAD build, constants have refcnt 2, not 1
189 skip("Test does not work with MAD", 5) if exists $Config{mad};
191 $a = eval '\"hello"';
192 ok(ref($a)) or print "# didn't get a ref from eval\n";
196 ok($@ eq "") or print "# died with $@\n";
198 ok($$b eq "hello") or print "# b is '$$b'\n";
200 ok(not $b) or print "# b didn't go away\n";