fix deep recursion when calling isa check within isa check
[gitmo/Moo.git] / xt / moose-lazy.t
CommitLineData
879ef22d 1use strictures 1;
2use Test::More;
879ef22d 3
4{
5 package LazyFrew;
6
7 our $default_ran = 0;
8 our $quoted_default_ran = 0;
9 our $builder_ran = 0;
10
11 use Moo::Role;
12 use Sub::Quote;
13
14 has frooh => (
15 is => 'rw',
16 default => sub {
17 $default_ran = 1;
18 'test frooh'
19 },
20 lazy => 1,
21 );
22
23 has frew => (
24 is => 'rw',
25 default => quote_sub(q{
efab9210 26 $$quoted_default_ran = 1;
879ef22d 27 'test frew'
efab9210 28 }, { '$quoted_default_ran' => \\$quoted_default_ran }),
879ef22d 29 lazy => 1,
30 );
31
32 has frioux => (
33 is => 'rw',
34 builder => 'build_frioux',
35 lazy => 1,
36 );
37
38 sub build_frioux {
39 $builder_ran = 1;
40 'test frioux'
41 }
42
43 package Bar;
44 use Moose;
45 with 'LazyFrew';
46}
47
48my $x = Bar->new;
49ok(!$LazyFrew::default_ran, 'default has not run yet');
50ok(!$LazyFrew::quoted_default_ran, 'quoted default has not run yet');
51ok(!$LazyFrew::builder_ran, 'builder has not run yet');
52
53is($x->frooh, 'test frooh', 'frooh defaulted correctly');
54
55ok($LazyFrew::default_ran, 'default ran');
56ok(!$LazyFrew::quoted_default_ran, 'quoted default has not run yet');
57ok(!$LazyFrew::builder_ran, 'builder has not run yet');
58
59is($x->frew, 'test frew', 'frew defaulted correctly');
60
61ok($LazyFrew::default_ran, 'default ran');
62ok($LazyFrew::quoted_default_ran, 'quoted default ran');
63ok(!$LazyFrew::builder_ran, 'builder has not run yet');
64
65is($x->frioux, 'test frioux', 'frioux built correctly');
66
67ok($LazyFrew::default_ran, 'default ran');
68ok($LazyFrew::quoted_default_ran, 'quoted default ran');
69ok($LazyFrew::builder_ran, 'builder ran');
70
71done_testing;