From: Dave Rolsky Date: Fri, 19 Nov 2010 15:15:01 +0000 (-0600) Subject: Fix error message generation when array or hash ref member fails type check in native... X-Git-Tag: 1.20~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ea829e77f657851c78cd65dd2b7ed05ce6c6ffff;p=gitmo%2FMoose.git Fix error message generation when array or hash ref member fails type check in native delegation --- diff --git a/Changes b/Changes index c95babb..4501c9b 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,15 @@ Also see Moose::Manual::Delta for more details of, and workarounds for, noteworthy changes. +NEXT + + [BUG FIXES] + + * When using native delegations, if an array or hash ref member failed a + type constraint check, Moose ended up erroring out with "Can't call method + "get_message" on unblessed reference" instead of generating a useful error + based on the failed type constraint. Reported by t0m. (Dave Rolsky) + 1.19 Tue, Nov 2, 2010 [BUG FIXES] diff --git a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm index 25d7997..1721523 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm @@ -108,7 +108,7 @@ sub _inline_check_member_constraint { return '$member_tc->($_) || ' . $self->_inline_throw_error( qq{"A new member value for '$attr_name' does not pass its type constraint because: "} - . ' . $member_tc->get_message($_)', + . ' . $member_tc_obj->get_message($_)', "data => \$_" ) . " for $new_value;"; } diff --git a/t/070_native_traits/011_array_subtypes.t b/t/070_native_traits/011_array_subtypes.t index 1c30ad4..6b38ae7 100644 --- a/t/070_native_traits/011_array_subtypes.t +++ b/t/070_native_traits/011_array_subtypes.t @@ -234,4 +234,32 @@ my $foo = Foo->new; ); } +{ + package Bar; + use Moose; +} + +{ + package HasArray; + use Moose; + + has objects => ( + isa => 'ArrayRef[Foo]', + traits => ['Array'], + handles => { + push_objects => 'push', + }, + ); +} + +{ + my $ha = HasArray->new(); + + like( + exception { $ha->push_objects( Bar->new ) }, + qr/\QValidation failed for 'Foo'/, + 'got expected error when pushing an object of the wrong class onto an array ref' + ); +} + done_testing;