MooClass->meta
[gitmo/Moo.git] / t / accessor-weaken.t
index 3b99264..ec5b069 100644 (file)
@@ -7,6 +7,12 @@ use Test::More;
   use Moo;
 
   has one => (is => 'ro', weak_ref => 1);
+
+  package Foo2;
+
+  use Moo;
+
+  has one => (is => 'lazy', weak_ref => 1, default => sub { {} });
 }
 
 my $ref = {};
@@ -14,7 +20,13 @@ my $foo = Foo->new(one => $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' };
@@ -26,6 +38,9 @@ if ($] < 5.008003) {
     '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');