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')
22 Scalar::Util->import(qw(weaken unweaken isweak));
24 # two references, one is weakened, the other is then undef'ed.
34 ok(ref($y) and ref($z));
37 ok(ref($y) and ref($z));
40 ok(not(defined($y) and defined($z)));
43 ok(not(defined($y) and defined($z)));
46 # one reference, which is weakened
63 # a circular structure
68 my $y = bless {}, 'Dest';
80 # a more complicated circular structure
85 my $y = bless {}, 'Dest';
86 my $x = bless {}, 'Dest';
97 # deleting a weakref before the other one
125 weaken($x->{Y} = \$a);
127 ok(!isweak($x->{Z}));
141 ok(isweak($y), '$y is weak after weaken()');
142 is($$y, "foo", '$y points at \"foo" after weaken()');
146 ok(!isweak($y), '$y is not weak after unweaken()');
147 is($$y, "foo", '$y points at \"foo" after unweaken()');
150 ok(defined $y, '$y still defined after undef $z');
153 # test weaken on a read only ref
155 # Doesn't work for older perls, see bug [perl #24506]
156 skip("Test does not work with perl < 5.8.3", 5) if $] < 5.008003;
158 # in a MAD build, constants have refcnt 2, not 1
159 skip("Test does not work with MAD", 5) if exists $Config{mad};
161 $a = eval '\"hello"';
162 ok(ref($a)) or print "# didn't get a ref from eval\n";
172 ok(not $b) or diag("b did not go away");