Support modifier by regexp
[gitmo/Mouse.git] / t / 100_bugs / 013_lazybuild_required_undef.t
CommitLineData
4c98ebb0 1package Foo;
2use 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
14has 'foo' => ( isa => 'Int | Undef', is => 'rw', coerce => 1, lazy_build => 1 );
15has 'bar' => ( isa => 'Int | Undef', is => 'rw', coerce => 1 );
16
17sub _build_foo { undef }
18
19package main;
20use Test::More tests => 4;
21
22ok ( !defined(Foo->new->bar), 'NonLazyBuild: Undef default' );
23ok ( !defined(Foo->new->bar(undef)), 'NonLazyBuild: Undef explicit' );
24
25ok ( !defined(Foo->new->foo), 'LazyBuild: Undef default/lazy_build' );
26
27## This test fails at the time of creation.
28ok ( !defined(Foo->new->foo(undef)), 'LazyBuild: Undef explicit' );
29
30
311;