9 has one => (is => 'ro', weak_ref => 1);
15 has one => (is => 'lazy', weak_ref => 1, default => sub { {} });
19 my $foo = Foo->new(one => $ref);
20 is($foo->one, $ref, 'value present');
21 ok(Scalar::Util::isweak($foo->{one}), 'value weakened');
23 ok(!defined $foo->{one}, 'weak value gone');
26 ok(my $ref2 = $foo2->one, 'value returned');
27 ok(Scalar::Util::isweak($foo2->{one}), 'value weakened');
29 ok(!defined $foo->{one}, 'weak value gone');
32 sub mk_ref { \ 'yay' };
33 my $foo_ro = eval { Foo->new(one => mk_ref()) };
37 qr/\QReference to readonly value in "one" can not be weakened on Perl < 5.8.3/,
38 'Expected exception thrown on old perls'
41 elsif ($^O eq 'cygwin' and $] < 5.012000) {
42 SKIP: { skip 'Static coderef reaping seems nonfunctional on cygwin < 5.12', 1 }
45 is(${$foo_ro->one},'yay', 'value present');
46 ok(Scalar::Util::isweak($foo_ro->{one}), 'value weakened');
48 { no warnings 'redefine'; *mk_ref = sub {} }
49 ok (!defined $foo_ro->{one}, 'optree reaped, ro static value gone');