2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
12 use Scalar::Util 'isweak';
24 ::ok(!$@, '... created the accessor method okay');
28 accessor => 'lazy_foo',
33 ::ok(!$@, '... created the lazy accessor method okay');
37 has 'foo_required' => (
38 accessor => 'foo_required',
42 ::ok(!$@, '... created the required accessor method okay');
46 accessor => 'foo_int',
50 ::ok(!$@, '... created the accessor method with type constraint okay');
54 accessor => 'foo_weak',
58 ::ok(!$@, '... created the accessor method with weak_ref okay');
62 accessor => 'foo_deref',
67 ::ok(!$@, '... created the accessor method with auto_deref okay');
70 has 'foo_deref_ro' => (
71 reader => 'foo_deref_ro',
76 ::ok(!$@, '... created the reader method with auto_deref okay');
79 has 'foo_deref_hash' => (
80 accessor => 'foo_deref_hash',
85 ::ok(!$@, '... created the reader method with auto_deref okay');
89 my $foo = Foo->new(foo_required => 'required');
95 is($foo->foo(), undef, '... got an unset value');
98 } '... foo wrote successfully';
99 is($foo->foo(), 100, '... got the correct set value');
101 ok(!isweak($foo->{foo}), '... it is not a weak reference');
107 } '... cannot create without the required attribute';
109 can_ok($foo, 'foo_required');
110 is($foo->foo_required(), 'required', '... got an unset value');
112 $foo->foo_required(100);
113 } '... foo_required wrote successfully';
114 is($foo->foo_required(), 100, '... got the correct set value');
117 $foo->foo_required(undef);
118 } '... foo_required did not die with undef';
120 is($foo->foo_required, undef, "value is undef");
122 ok(!isweak($foo->{foo_required}), '... it is not a weak reference');
126 ok(!exists($foo->{lazy_foo}), '... no value in lazy_foo slot');
128 can_ok($foo, 'lazy_foo');
129 is($foo->lazy_foo(), 10, '... got an deferred value');
131 # with type constraint
133 can_ok($foo, 'foo_int');
134 is($foo->foo_int(), undef, '... got an unset value');
137 } '... foo_int wrote successfully';
138 is($foo->foo_int(), 100, '... got the correct set value');
141 $foo->foo_int("Foo");
142 } '... foo_int died successfully';
144 ok(!isweak($foo->{foo_int}), '... it is not a weak reference');
150 can_ok($foo, 'foo_weak');
151 is($foo->foo_weak(), undef, '... got an unset value');
153 $foo->foo_weak($test);
154 } '... foo_weak wrote successfully';
155 is($foo->foo_weak(), $test, '... got the correct set value');
157 ok(isweak($foo->{foo_weak}), '... it is a weak reference');
159 can_ok( $foo, 'foo_deref');
160 is_deeply( [$foo->foo_deref()], [], '... default default value');
163 @list = $foo->foo_deref();
164 } "... doesn't deref undef value";
165 is_deeply( \@list, [], "returns empty list in list context");
168 $foo->foo_deref( [ qw/foo bar gorch/ ] );
169 } '... foo_deref wrote successfully';
171 is( Scalar::Util::reftype( scalar $foo->foo_deref() ), "ARRAY", "returns an array reference in scalar context" );
172 is_deeply( scalar($foo->foo_deref()), [ qw/foo bar gorch/ ], "correct array" );
174 is( scalar( () = $foo->foo_deref() ), 3, "returns list in list context" );
175 is_deeply( [ $foo->foo_deref() ], [ qw/foo bar gorch/ ], "correct list" );
178 can_ok( $foo, 'foo_deref' );
179 is_deeply( [$foo->foo_deref_ro()], [], "... default default value" );
182 $foo->foo_deref_ro( [] );
185 $foo->{foo_deref_ro} = [qw/la la la/];
187 is_deeply( scalar($foo->foo_deref_ro()), [qw/la la la/], "scalar context ro" );
188 is_deeply( [ $foo->foo_deref_ro() ], [qw/la la la/], "list context ro" );
190 can_ok( $foo, 'foo_deref_hash' );
191 is_deeply( { $foo->foo_deref_hash() }, {}, "... default default value" );
195 %hash = $foo->foo_deref_hash();
196 } "... doesn't deref undef value";
197 is_deeply( \%hash, {}, "returns empty list in list context");
200 $foo->foo_deref_hash( { foo => 1, bar => 2 } );
201 } '... foo_deref_hash wrote successfully';
203 is_deeply( scalar($foo->foo_deref_hash), { foo => 1, bar => 2 }, "scalar context" );
205 %hash = $foo->foo_deref_hash;
206 is_deeply( \%hash, { foo => 1, bar => 2 }, "list context");