6 use Scalar::Util 'isweak';
8 use Test::More tests => 26;
19 has 'bar' => (is => 'rw',
22 my ($self, $bar) = @_;
23 $bar->foo($self) if defined $bar;
26 has 'baz' => (writer => 'set_baz',
30 my ($self, $baz) = @_;
38 has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);
43 has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);
58 } '... did not die setting bar';
60 is($foo->bar, $bar, '... set the value foo.bar correctly');
61 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
63 ok(isweak($bar->{foo}), '... bar.foo is a weak reference');
67 } '... did not die un-setting bar';
69 is($foo->bar, undef, '... set the value foo.bar correctly');
70 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
76 } '... did not die setting baz';
78 is($foo->get_baz, $baz, '... set the value foo.baz correctly');
79 is($baz->foo, $foo, '... which in turn set the value baz.foo correctly');
81 ok(isweak($baz->{foo}), '... baz.foo is a weak reference');
91 my $foo = Foo->new(bar => $bar, baz => $baz);
94 is($foo->bar, $bar, '... set the value foo.bar correctly');
95 is($bar->foo, $foo, '... which in turn set the value bar.foo correctly');
97 ok(isweak($bar->{foo}), '... bar.foo is a weak reference');
99 is($foo->get_baz, $baz, '... set the value foo.baz correctly');
100 is($baz->foo, $foo, '... which in turn set the value baz.foo correctly');
102 ok(isweak($baz->{foo}), '... baz.foo is a weak reference');
112 has('bling' => (is => 'rw', trigger => 'Fail'));
113 } '... a trigger must be a CODE ref';
116 has('bling' => (is => 'rw', trigger => []));
117 } '... a trigger must be a CODE ref';