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