From: Matt S Trout Date: Wed, 18 Jul 2012 19:16:09 +0000 (+0000) Subject: die wrap with prefix for attribute isa X-Git-Tag: v1.000000~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc65d74453e1910cd20e7771a2a08898f30594ae;p=gitmo%2FMoo.git die wrap with prefix for attribute isa --- diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 0918912..e7eebb4 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -308,7 +308,13 @@ sub generate_isa_check { sub _generate_isa_check { my ($self, $name, $value, $check) = @_; - $self->_generate_call_code($name, 'isa_check', $value, $check); + "{\n" + .' my $sig_die = $SIG{__DIE__} || sub { die $_[0] };'."\n" + .' local $SIG{__DIE__} = sub {'."\n" + .' $sig_die->(ref($_[0]) ? $_[0] : q{isa check for '.perlstring($name).' failed: }.$_[0]);'."\n" + .' };'."\n" + .$self->_generate_call_code($name, 'isa_check', $value, $check) + ."}\n" } sub _generate_call_code { diff --git a/t/accessor-isa.t b/t/accessor-isa.t index 2ddc020..69d66c1 100644 --- a/t/accessor-isa.t +++ b/t/accessor-isa.t @@ -11,7 +11,8 @@ sub run_for { like( exception { $obj->less_than_three(4) }, - qr/4 is not less than three/, "exception thrown on bad set (${class})" + qr/isa check for "less_than_three" failed: 4 is not less than three/, + "exception thrown on bad set (${class})" ); is($obj->less_than_three, 1, "initial value remains after bad set (${class})"); @@ -29,7 +30,7 @@ sub run_for { is(exception { $class->new }, undef, "no exception with no value (${class})"); like( exception { $class->new(less_than_three => 12) }, - qr/12 is not less than three/, + qr/isa check for "less_than_three" failed: 12 is not less than three/, "exception thrown on bad constructor arg (${class})" ); } @@ -99,7 +100,7 @@ run_for 'Baz'; like( exception { LazyFoo->new->less_than_three }, - qr/4 is not less than three/, + qr/isa check for "less_than_three" failed: 4 is not less than three/, "exception thrown on bad builder return value (LazyFoo)" );