From: Evan Carroll Date: Tue, 3 Jun 2008 17:06:52 +0000 (+0000) Subject: added a test for required=>1,undef with type that permits undef, using lazy_build X-Git-Tag: 0_55~127 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e5321a246e327b076427c2106bca8a1c20991058;p=gitmo%2FMoose.git added a test for required=>1,undef with type that permits undef, using lazy_build --- diff --git a/t/100_bugs/013_lazybuild_required_undef.t b/t/100_bugs/013_lazybuild_required_undef.t new file mode 100644 index 0000000..6a6d4fc --- /dev/null +++ b/t/100_bugs/013_lazybuild_required_undef.t @@ -0,0 +1,31 @@ +package Foo; +use Moose; + +## Problem: +## lazy_build sets required => 1 +## required does not permit setting to undef + +## Possible solutions: +#### remove required => 1 +#### check the attr to see if it accepts Undef (Maybe[], | Undef) +#### or, make required accept undef and use a predicate test + + +has 'foo' => ( isa => 'Int | Undef', is => 'rw', coerce => 1, lazy_build => 1 ); +has 'bar' => ( isa => 'Int | Undef', is => 'rw', coerce => 1 ); + +sub _build_foo { undef } + +package main; +use Test::More tests => 4; + +ok ( !defined(Foo->new->bar), 'NonLazyBuild: Undef default' ); +ok ( !defined(Foo->new->bar(undef)), 'NonLazyBuild: Undef explicit' ); + +ok ( !defined(Foo->new->foo), 'LazyBuild: Undef default/lazy_build' ); + +## This test fails at the time of creation. +ok ( !defined(Foo->new->foo(undef)), 'LazyBuild: Undef explicit' ); + + +1;