8 my $obj = $class->new(less_than_three => 1);
10 is($obj->less_than_three, 1, "initial value set (${class})");
13 exception { $obj->less_than_three(4) },
14 qr/isa check for "less_than_three" failed: 4 is not less than three/,
15 "exception thrown on bad set (${class})"
18 is($obj->less_than_three, 1, "initial value remains after bad set (${class})");
23 exception { $ret = $obj->less_than_three(2) },
24 undef, "no exception on correct set (${class})"
27 is($ret, 2, "correct setter return (${class})");
28 is($obj->less_than_three, 2, "correct getter return (${class})");
30 is(exception { $class->new }, undef, "no exception with no value (${class})");
32 exception { $class->new(less_than_three => 12) },
33 qr/isa check for "less_than_three" failed: 12 is not less than three/,
34 "exception thrown on bad constructor arg (${class})"
43 has less_than_three => (
45 isa => sub { die "$_[0] is not less than three" unless $_[0] < 3 }
57 has less_than_three => (
61 die "$x is not less than three" unless $x < 3
74 has less_than_three => (
79 die "$value is not less than ${word}" unless $value < $limit
81 { '$limit' => \3, '$word' => \'three' }
96 has less_than_three => (
98 isa => quote_sub(q{ die "$_[0] is not less than three" unless $_[0] < 3 })
101 sub _build_less_than_three { $lt3 }
106 my $lazyfoo = LazyFoo->new;
108 exception { $lazyfoo->less_than_three },
109 qr/isa check for "less_than_three" failed: 4 is not less than three/,
110 "exception thrown on bad builder return value (LazyFoo)"
116 exception { $lazyfoo->less_than_three },
118 'Corrected builder value on existing object returned ok'
121 is(LazyFoo->new->less_than_three, 2, 'Correct builder value returned ok');
132 my $attr = $Method::Generate::Accessor::CurrentAttribute;
133 die bless [@$attr{'name', 'init_arg', 'step'}], 'MyException';
135 init_arg => 'attr_1',
139 my $e = exception { Fizz->new(attr_1 => 5) };
143 'Exception objects passed though correctly',
146 is($e->[0], 'attr1', 'attribute name available in isa check');
147 is($e->[1], 'attr_1', 'attribute init_arg available in isa check');
148 is($e->[2], 'isa check', 'step available in isa check');
152 local $SIG{__DIE__} = sub { $called++; die $_[0] };
153 my $e = exception { Fizz->new(attr_1 => 5) };
154 is($called, 1, '__DIE__ handler called if set')