From: Matt S Trout Date: Tue, 26 Jun 2012 19:30:25 +0000 (+0000) Subject: isa checks on builders X-Git-Tag: v0.091010~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef21bc32074776d8e3a358806b02086635849743;p=gitmo%2FMoo.git isa checks on builders --- diff --git a/Changes b/Changes index 0a15a5f..bec01fa 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - isa checks on builders - additional quote_sub docs - remove multi-populate code to fix exists/defined new() bug - document move to #moose and include repository metadata diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index fe268ba..01acab8 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -185,7 +185,12 @@ sub _generate_get { 'do { '.$self->_generate_use_default( '$_[0]', $name, $spec, $self->_generate_simple_has('$_[0]', $name, $spec), - ).'; '.$simple.' }'; + ).'; ' + .($spec->{isa} + ?($self->_generate_isa_check($name, $simple, $spec->{isa}).'; ') + :'' + ) + .$simple.' }'; } } diff --git a/t/accessor-isa.t b/t/accessor-isa.t index 1e8f88f..2ddc020 100644 --- a/t/accessor-isa.t +++ b/t/accessor-isa.t @@ -84,4 +84,23 @@ run_for 'Bar'; run_for 'Baz'; +{ + package LazyFoo; + + use Moo; + + has less_than_three => ( + is => 'lazy', + isa => sub { die "$_[0] is not less than three" unless $_[0] < 3 } + ); + + sub _build_less_than_three { 4 } +} + +like( + exception { LazyFoo->new->less_than_three }, + qr/4 is not less than three/, + "exception thrown on bad builder return value (LazyFoo)" +); + done_testing;