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 is(ref $y, "SCALAR", '$y is still a SCALAR ref after unweaken()');
147 ok(!isweak($y), '$y is not weak after unweaken()');
148 is($$y, "foo", '$y points at \"foo" after unweaken()');
151 ok(defined $y, '$y still defined after undef $z');
154 # test weaken on a read only ref
156 # Doesn't work for older perls, see bug [perl #24506]
157 skip("Test does not work with perl < 5.8.3", 5) if $] < 5.008003;
159 # in a MAD build, constants have refcnt 2, not 1
160 skip("Test does not work with MAD", 5) if exists $Config{mad};
162 $a = eval '\"hello"';
163 ok(ref($a)) or print "# didn't get a ref from eval\n";
173 ok(not $b) or diag("b did not go away");