add tests for inheriting an attribute and adding lazy_build by ether on #moose
[gitmo/Moose.git] / t / 100_bugs / 029_lazy_build_inherited.t
CommitLineData
04c8370f 1use strict;
2use warnings;
3
4use Test::More tests => 12;
5use Test::Exception;
6use Test::NoWarnings;
7
8{
9 package Parent;
10 use Moose;
11 has attr => ( is => 'rw', isa => 'Str' );
12}
13
14{
15 package Child;
16 use Moose;
17 extends 'Parent';
18
19 has '+attr' => ( lazy_build => 1 );
20 sub _build_attr
21 {
22 return 'value';
23 }
24}
25
26package main;
27
28my $parent = Parent->new();
29my $child = Child->new();
30
31ok(!$parent->meta->get_attribute('attr')->is_lazy_build,
32 'attribute in parent does not have lazy_build trait');
33ok(!$parent->meta->get_attribute('attr')->is_lazy,
34 'attribute in parent does not have lazy trait');
35ok(!$parent->meta->get_attribute('attr')->has_builder,
36 'attribute in parent does not have a builder method');
37ok(!$parent->meta->get_attribute('attr')->has_clearer,
38 'attribute in parent does not have a clearer method');
39ok(!$parent->meta->get_attribute('attr')->has_predicate,
40 'attribute in parent does not have a predicate method');
41
42ok($child->meta->get_attribute('attr')->is_lazy_build,
43 'attribute in child has the lazy_build trait');
44ok($child->meta->get_attribute('attr')->is_lazy,
45 'attribute in child has the lazy trait');
46ok($child->meta->get_attribute('attr')->has_builder,
47 'attribute in child has a builder method');
48ok($child->meta->get_attribute('attr')->has_clearer,
49 'attribute in child has a clearer method');
50ok($child->meta->get_attribute('attr')->has_predicate,
51 'attribute in child has a predicate method');
52
53is($child->attr, 'value', 'attribute defined as lazy_build in child is properly built');