support weak_ref
[gitmo/Moo.git] / t / accessor-weaken.t
diff --git a/t/accessor-weaken.t b/t/accessor-weaken.t
new file mode 100644 (file)
index 0000000..2bfecbe
--- /dev/null
@@ -0,0 +1,19 @@
+use strictures 1;
+use Test::More;
+
+{
+  package Foo;
+
+  use Moo;
+
+  has one => (is => 'ro', weak_ref => 1);
+}
+
+my $ref = \'yay';
+
+my $foo = Foo->new(one => $ref);
+
+is(${$foo->one},'yay', 'value present');
+ok(Scalar::Util::isweak($foo->{one}), 'value weakened');
+
+done_testing;