Commit | Line | Data |
879ef22d |
1 | use strictures 1; |
2 | use 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 | |
48 | my $x = Bar->new; |
49 | ok(!$LazyFrew::default_ran, 'default has not run yet'); |
50 | ok(!$LazyFrew::quoted_default_ran, 'quoted default has not run yet'); |
51 | ok(!$LazyFrew::builder_ran, 'builder has not run yet'); |
52 | |
53 | is($x->frooh, 'test frooh', 'frooh defaulted correctly'); |
54 | |
55 | ok($LazyFrew::default_ran, 'default ran'); |
56 | ok(!$LazyFrew::quoted_default_ran, 'quoted default has not run yet'); |
57 | ok(!$LazyFrew::builder_ran, 'builder has not run yet'); |
58 | |
59 | is($x->frew, 'test frew', 'frew defaulted correctly'); |
60 | |
61 | ok($LazyFrew::default_ran, 'default ran'); |
62 | ok($LazyFrew::quoted_default_ran, 'quoted default ran'); |
63 | ok(!$LazyFrew::builder_ran, 'builder has not run yet'); |
64 | |
65 | is($x->frioux, 'test frioux', 'frioux built correctly'); |
66 | |
67 | ok($LazyFrew::default_ran, 'default ran'); |
68 | ok($LazyFrew::quoted_default_ran, 'quoted default ran'); |
69 | ok($LazyFrew::builder_ran, 'builder ran'); |
70 | |
71 | done_testing; |