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