Implement strict constructors, which will warn unkown constructor arguments
[gitmo/Mouse.git] / t / 100_bugs / 013_lazybuild_required_undef.t
1 package Foo;
2 use Mouse;
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
14 has 'foo' => ( isa => 'Int | Undef', is => 'rw', coerce => 1, lazy_build => 1 );
15 has 'bar' => ( isa => 'Int | Undef', is => 'rw', coerce => 1 );
16
17 sub _build_foo { undef }
18
19 package main;
20 use Test::More tests => 4;
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
30
31 1;