9 use Scalar::Util 'isweak';
22 ::ok(!$@, '... created the writer method okay');
25 has 'foo_required' => (
26 reader => 'get_foo_required',
27 writer => 'set_foo_required',
31 ::ok(!$@, '... created the required writer method okay');
35 reader => 'get_foo_int',
36 writer => 'set_foo_int',
40 ::ok(!$@, '... created the writer method with type constraint okay');
44 reader => 'get_foo_weak',
45 writer => 'set_foo_weak',
49 ::ok(!$@, '... created the writer method with weak_ref okay');
53 my $foo = Foo->new(foo_required => 'required');
58 can_ok($foo, 'set_foo');
59 is($foo->get_foo(), undef, '... got an unset value');
62 }, undef, '... set_foo wrote successfully' );
63 is($foo->get_foo(), 100, '... got the correct set value');
65 ok(!isweak($foo->{foo}), '... it is not a weak reference');
71 }, undef, '... cannot create without the required attribute' );
73 can_ok($foo, 'set_foo_required');
74 is($foo->get_foo_required(), 'required', '... got an unset value');
76 $foo->set_foo_required(100);
77 }, undef, '... set_foo_required wrote successfully' );
78 is($foo->get_foo_required(), 100, '... got the correct set value');
81 $foo->set_foo_required();
82 }, undef, '... set_foo_required died successfully with no value' );
85 $foo->set_foo_required(undef);
86 }, undef, '... set_foo_required did accept undef' );
88 ok(!isweak($foo->{foo_required}), '... it is not a weak reference');
90 # with type constraint
92 can_ok($foo, 'set_foo_int');
93 is($foo->get_foo_int(), undef, '... got an unset value');
95 $foo->set_foo_int(100);
96 }, undef, '... set_foo_int wrote successfully' );
97 is($foo->get_foo_int(), 100, '... got the correct set value');
100 $foo->set_foo_int("Foo");
101 }, undef, '... set_foo_int died successfully' );
103 ok(!isweak($foo->{foo_int}), '... it is not a weak reference');
109 can_ok($foo, 'set_foo_weak');
110 is($foo->get_foo_weak(), undef, '... got an unset value');
112 $foo->set_foo_weak($test);
113 }, undef, '... set_foo_weak wrote successfully' );
114 is($foo->get_foo_weak(), $test, '... got the correct set value');
116 ok(isweak($foo->{foo_weak}), '... it is a weak reference');