From: Matt S Trout Date: Thu, 26 Apr 2012 18:49:52 +0000 (+0000) Subject: BUILDARGS exception X-Git-Tag: v0.091000~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=09233107cb7ec24a9d679b118773ecfcac217552;p=gitmo%2FMoo.git BUILDARGS exception --- diff --git a/Changes b/Changes index d48047c..754a20d 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - better error message for broken BUILDARGS - provide 'no Moo::sification' to forcibly disable metaclass inflation - switch to Devel::GlobalDestruction to correctly disarm the Moo::sification trigger under threads diff --git a/lib/Method/Generate/Constructor.pm b/lib/Method/Generate/Constructor.pm index 707341d..86c5afb 100644 --- a/lib/Method/Generate/Constructor.pm +++ b/lib/Method/Generate/Constructor.pm @@ -90,7 +90,9 @@ sub _cap_call { sub _generate_args_via_buildargs { my ($self) = @_; - q{ my $args = $class->BUILDARGS(@_);}."\n"; + q{ my $args = $class->BUILDARGS(@_);}."\n" + .q{ die "BUILDARGS did not return a hashref" unless ref($args) eq 'HASH';} + ."\n"; } # inlined from Moo::Object - update that first. diff --git a/t/buildargs-error.t b/t/buildargs-error.t index 85afbe8..97376c4 100644 --- a/t/buildargs-error.t +++ b/t/buildargs-error.t @@ -1,5 +1,6 @@ use strictures 1; use Test::More; +use Test::Fatal; { package Foo; @@ -15,7 +16,11 @@ use Test::More; } } -my $f = Foo->new({ bar => 1, baz => 1 }); +like( + exception { Foo->new({ bar => 1, baz => 1 }) }, + qr/BUILDARGS did not return a hashref/, + 'Sensible error message' +); done_testing;