Commit | Line | Data |
bdef60b4 |
1 | use strict; |
2 | use Test::More tests => 4; |
3 | |
4c98ebb0 |
4 | package Foo; |
5 | use Mouse; |
6 | |
7 | ## Problem: |
8 | ## lazy_build sets required => 1 |
9 | ## required does not permit setting to undef |
10 | |
11 | ## Possible solutions: |
12 | #### remove required => 1 |
13 | #### check the attr to see if it accepts Undef (Maybe[], | Undef) |
14 | #### or, make required accept undef and use a predicate test |
15 | |
16 | |
17 | has 'foo' => ( isa => 'Int | Undef', is => 'rw', coerce => 1, lazy_build => 1 ); |
18 | has 'bar' => ( isa => 'Int | Undef', is => 'rw', coerce => 1 ); |
19 | |
20 | sub _build_foo { undef } |
21 | |
22 | package main; |
4c98ebb0 |
23 | |
24 | ok ( !defined(Foo->new->bar), 'NonLazyBuild: Undef default' ); |
25 | ok ( !defined(Foo->new->bar(undef)), 'NonLazyBuild: Undef explicit' ); |
26 | |
27 | ok ( !defined(Foo->new->foo), 'LazyBuild: Undef default/lazy_build' ); |
28 | |
29 | ## This test fails at the time of creation. |
30 | ok ( !defined(Foo->new->foo(undef)), 'LazyBuild: Undef explicit' ); |