6 use Test::More tests => 29;
9 use Scalar::Util 'isweak';
23 ::ok(!$@, '... created the writer method okay');
26 has 'foo_required' => (
27 reader => 'get_foo_required',
28 writer => 'set_foo_required',
32 ::ok(!$@, '... created the required writer method okay');
36 reader => 'get_foo_int',
37 writer => 'set_foo_int',
41 ::ok(!$@, '... created the writer method with type constraint okay');
45 reader => 'get_foo_weak',
46 writer => 'set_foo_weak',
50 ::ok(!$@, '... created the writer method with weak_ref okay');
54 my $foo = Foo->new(foo_required => 'required');
59 can_ok($foo, 'set_foo');
60 is($foo->get_foo(), undef, '... got an unset value');
63 } '... set_foo wrote successfully';
64 is($foo->get_foo(), 100, '... got the correct set value');
66 ok(!isweak($foo->{foo}), '... it is not a weak reference');
72 } '... cannot create without the required attribute';
74 can_ok($foo, 'set_foo_required');
75 is($foo->get_foo_required(), 'required', '... got an unset value');
77 $foo->set_foo_required(100);
78 } '... set_foo_required wrote successfully';
79 is($foo->get_foo_required(), 100, '... got the correct set value');
82 $foo->set_foo_required();
83 } '... set_foo_required died successfully with no value';
86 $foo->set_foo_required(undef);
87 } '... set_foo_required did accept undef';
89 ok(!isweak($foo->{foo_required}), '... it is not a weak reference');
91 # with type constraint
93 can_ok($foo, 'set_foo_int');
94 is($foo->get_foo_int(), undef, '... got an unset value');
96 $foo->set_foo_int(100);
97 } '... set_foo_int wrote successfully';
98 is($foo->get_foo_int(), 100, '... got the correct set value');
101 $foo->set_foo_int("Foo");
102 } '... set_foo_int died successfully';
104 ok(!isweak($foo->{foo_int}), '... it is not a weak reference');
110 can_ok($foo, 'set_foo_weak');
111 is($foo->get_foo_weak(), undef, '... got an unset value');
113 $foo->set_foo_weak($test);
114 } '... set_foo_weak wrote successfully';
115 is($foo->get_foo_weak(), $test, '... got the correct set value');
117 ok(isweak($foo->{foo_weak}), '... it is a weak reference');