Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 100_bugs / 013_lazybuild_required_undef.t
CommitLineData
4c98ebb0 1package Foo;
ee5e6a03 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4c98ebb0 5use 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
ee5e6a03 17has 'foo' => ( isa => 'Int | Undef', is => 'rw', lazy_build => 1 );
18has 'bar' => ( isa => 'Int | Undef', is => 'rw' );
4c98ebb0 19
20sub _build_foo { undef }
21
22package main;
ee5e6a03 23use Test::More;
4c98ebb0 24
25ok ( !defined(Foo->new->bar), 'NonLazyBuild: Undef default' );
26ok ( !defined(Foo->new->bar(undef)), 'NonLazyBuild: Undef explicit' );
27
28ok ( !defined(Foo->new->foo), 'LazyBuild: Undef default/lazy_build' );
29
30## This test fails at the time of creation.
31ok ( !defined(Foo->new->foo(undef)), 'LazyBuild: Undef explicit' );
ee5e6a03 32
33done_testing;