From: Graham Knop Date: Mon, 24 Jun 2013 03:07:26 +0000 (-0400) Subject: tests for $CurrentAttribute and __DIE__ handlers in isa checks X-Git-Tag: v1.003000~37 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0c0971f50c8d61689d45076547f44dd9cae34c7d;p=gitmo%2FMoo.git tests for $CurrentAttribute and __DIE__ handlers in isa checks --- diff --git a/t/accessor-isa.t b/t/accessor-isa.t index 01a005c..8f44500 100644 --- a/t/accessor-isa.t +++ b/t/accessor-isa.t @@ -120,4 +120,38 @@ is( is(LazyFoo->new->less_than_three, 2, 'Correct builder value returned ok'); +{ + package Fizz; + + use Moo; + + has attr1 => ( + is => 'ro', + isa => sub { + no warnings 'once'; + my $attr = $Method::Generate::Accessor::CurrentAttribute; + die bless [@$attr{'name', 'init_arg', 'step'}], 'MyException'; + }, + init_arg => 'attr_1', + ); +} + +my $e = exception { Fizz->new(attr_1 => 5) }; +is( + ref($e), + 'MyException', + 'Exception objects passed though correctly', +); + +is($e->[0], 'attr1', 'attribute name available in isa check'); +is($e->[1], 'attr_1', 'attribute init_arg available in isa check'); +is($e->[2], 'isa check', 'step available in isa check'); + +{ + my $called; + local $SIG{__DIE__} = sub { $called++; die $_[0] }; + my $e = exception { Fizz->new(attr_1 => 5) }; + is($called, 1, '__DIE__ handler called if set') +} + done_testing;