We only need local $? if we inline calls to DEMOLISH
[gitmo/Moose.git] / t / attributes / inherit_lazy_build.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 {
7
8     package Parent;
9     use Moose;
10     has attr => ( is => 'rw', isa => 'Str' );
11 }
12
13 {
14     package Child;
15     use Moose;
16     extends 'Parent';
17
18     has '+attr' => ( lazy_build => 1 );
19
20     sub _build_attr {
21         return 'value';
22     }
23 }
24
25 my $parent = Parent->new();
26 my $child  = Child->new();
27
28 ok(
29     !$parent->meta->get_attribute('attr')->is_lazy_build,
30     'attribute in parent does not have lazy_build trait'
31 );
32 ok(
33     !$parent->meta->get_attribute('attr')->is_lazy,
34     'attribute in parent does not have lazy trait'
35 );
36 ok(
37     !$parent->meta->get_attribute('attr')->has_builder,
38     'attribute in parent does not have a builder method'
39 );
40 ok(
41     !$parent->meta->get_attribute('attr')->has_clearer,
42     'attribute in parent does not have a clearer method'
43 );
44 ok(
45     !$parent->meta->get_attribute('attr')->has_predicate,
46     'attribute in parent does not have a predicate method'
47 );
48
49 ok(
50     $child->meta->get_attribute('attr')->is_lazy_build,
51     'attribute in child has the lazy_build trait'
52 );
53 ok(
54     $child->meta->get_attribute('attr')->is_lazy,
55     'attribute in child has the lazy trait'
56 );
57 ok(
58     $child->meta->get_attribute('attr')->has_builder,
59     'attribute in child has a builder method'
60 );
61 ok(
62     $child->meta->get_attribute('attr')->has_clearer,
63     'attribute in child has a clearer method'
64 );
65 ok(
66     $child->meta->get_attribute('attr')->has_predicate,
67     'attribute in child has a predicate method'
68 );
69
70 is(
71     $child->attr, 'value',
72     'attribute defined as lazy_build in child is properly built'
73 );
74
75 done_testing;