6 use Scalar::Util 'isweak';
8 use Test::More tests => 24;
21 has 'bar' => (is => 'rw',
24 my ($self, $bar) = @_;
25 $bar->foo($self) if defined $bar;
28 has 'baz' => (writer => 'set_baz',
32 my ($self, $baz) = @_;
42 has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);
49 has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);
64 } '... did not die setting bar';
66 is($foo->bar, $bar, '... set the value foo.bar correctly');
67 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
69 ok(isweak($bar->{foo}), '... bar.foo is a weak reference');
73 } '... did not die un-setting bar';
75 is($foo->bar, undef, '... set the value foo.bar correctly');
76 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
82 } '... did not die setting baz';
84 is($foo->get_baz, $baz, '... set the value foo.baz correctly');
85 is($baz->foo, $foo, '... which in turn set the value baz.foo correctly');
87 ok(isweak($baz->{foo}), '... baz.foo is a weak reference');
97 my $foo = Foo->new(bar => $bar, baz => $baz);
100 is($foo->bar, $bar, '... set the value foo.bar correctly');
101 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
103 ok(isweak($bar->{foo}), '... bar.foo is a weak reference');
105 is($foo->get_baz, $baz, '... set the value foo.baz correctly');
106 is($baz->foo, $foo, '... which in turn set the value baz.foo correctly');
108 ok(isweak($baz->{foo}), '... baz.foo is a weak reference');