6 use Test::More tests => 33;
9 use Scalar::Util 'isweak';
26 ::ok(!$@, '... created the accessor method okay');
30 accessor => 'lazy_foo',
35 ::ok(!$@, '... created the lazy accessor method okay');
39 has 'foo_required' => (
40 accessor => 'foo_required',
44 ::ok(!$@, '... created the required accessor method okay');
48 accessor => 'foo_int',
52 ::ok(!$@, '... created the accessor method with type constraint okay');
56 accessor => 'foo_weak',
60 ::ok(!$@, '... created the accessor method with weak_ref okay');
64 my $foo = Foo->new(foo_required => 'required');
70 is($foo->foo(), undef, '... got an unset value');
73 } '... foo wrote successfully';
74 is($foo->foo(), 100, '... got the correct set value');
76 ok(!isweak($foo->{foo}), '... it is not a weak reference');
82 } '... cannot create without the required attribute';
84 can_ok($foo, 'foo_required');
85 is($foo->foo_required(), 'required', '... got an unset value');
87 $foo->foo_required(100);
88 } '... foo_required wrote successfully';
89 is($foo->foo_required(), 100, '... got the correct set value');
92 $foo->foo_required(undef);
93 } '... foo_required died successfully';
95 ok(!isweak($foo->{foo_required}), '... it is not a weak reference');
99 ok(!exists($foo->{lazy_foo}), '... no value in lazy_foo slot');
101 can_ok($foo, 'lazy_foo');
102 is($foo->lazy_foo(), 10, '... got an deferred value');
104 # with type constraint
106 can_ok($foo, 'foo_int');
107 is($foo->foo_int(), undef, '... got an unset value');
110 } '... foo_int wrote successfully';
111 is($foo->foo_int(), 100, '... got the correct set value');
114 $foo->foo_int("Foo");
115 } '... foo_int died successfully';
117 ok(!isweak($foo->{foo_int}), '... it is not a weak reference');
123 can_ok($foo, 'foo_weak');
124 is($foo->foo_weak(), undef, '... got an unset value');
126 $foo->foo_weak($test);
127 } '... foo_weak wrote successfully';
128 is($foo->foo_weak(), $test, '... got the correct set value');
130 ok(isweak($foo->{foo_weak}), '... it is a weak reference');