use Moo;
has one => (is => 'ro', weak_ref => 1);
+
+ package Foo2;
+
+ use Moo;
+
+ has one => (is => 'lazy', weak_ref => 1, default => sub { {} });
}
my $ref = {};
is($foo->one, $ref, 'value present');
ok(Scalar::Util::isweak($foo->{one}), 'value weakened');
undef $ref;
-ok (!defined $foo->{one}, 'weak value gone');
+ok(!defined $foo->{one}, 'weak value gone');
+
+my $foo2 = Foo2->new;
+ok(my $ref2 = $foo2->one, 'value returned');
+ok(Scalar::Util::isweak($foo2->{one}), 'value weakened');
+undef $ref2;
+ok(!defined $foo->{one}, 'weak value gone');
# test readonly SVs
sub mk_ref { \ 'yay' };
'Expected exception thrown on old perls'
);
}
+elsif ($^O eq 'cygwin' and $] < 5.012000) {
+ SKIP: { skip 'Static coderef reaping seems nonfunctional on cygwin < 5.12', 1 }
+}
else {
is(${$foo_ro->one},'yay', 'value present');
ok(Scalar::Util::isweak($foo_ro->{one}), 'value weakened');