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