6 use Scalar::Util 'isweak';
8 use Test::More tests => 25;
17 has 'bar' => (is => 'rw',
20 my ($self, $bar) = @_;
21 $bar->foo($self) if defined $bar;
24 has 'baz' => (writer => 'set_baz',
28 my ($self, $baz) = @_;
36 has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);
41 has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);
56 } '... did not die setting bar';
58 is($foo->bar, $bar, '... set the value foo.bar correctly');
59 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
61 ok(isweak($bar->{foo}), '... bar.foo is a weak reference');
65 } '... did not die un-setting bar';
67 is($foo->bar, undef, '... set the value foo.bar correctly');
68 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
74 } '... did not die setting baz';
76 is($foo->get_baz, $baz, '... set the value foo.baz correctly');
77 is($baz->foo, $foo, '... which in turn set the value baz.foo correctly');
79 ok(isweak($baz->{foo}), '... baz.foo is a weak reference');
89 my $foo = Foo->new(bar => $bar, baz => $baz);
92 is($foo->bar, $bar, '... set the value foo.bar correctly');
93 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
95 ok(isweak($bar->{foo}), '... bar.foo is a weak reference');
97 is($foo->get_baz, $baz, '... set the value foo.baz correctly');
98 is($baz->foo, $foo, '... which in turn set the value baz.foo correctly');
100 ok(isweak($baz->{foo}), '... baz.foo is a weak reference');
110 has('bling' => (is => 'rw', trigger => 'Fail'));
111 } '... a trigger must be a CODE ref';
114 has('bling' => (is => 'rw', trigger => []));
115 } '... a trigger must be a CODE ref';