8 use Moose::Util::TypeConstraints;
10 subtype 'Death', as 'Int', where { $_ == 1 };
11 coerce 'Death', from 'Any', via { confess };
15 my ($attr_foo_line, $attr_bar_line, $ctor_line);
25 $attr_foo_line = __LINE__ - 5;
32 $attr_bar_line = __LINE__ - 5;
34 __PACKAGE__->meta->make_immutable;
35 $ctor_line = __LINE__ - 1;
39 exception { Foo->new(foo => 2) },
40 qr/called at constructor Foo::new \(defined at $0 line $ctor_line\)/,
41 "got definition context for the constructor"
45 exception { my $f = Foo->new(foo => 1); $f->foo(2) },
46 qr/called at accessor Foo::foo \(defined at $0 line $attr_foo_line\)/,
47 "got definition context for the accessor"
51 exception { my $f = Foo->new(foo => 1); $f->baz(2) },
52 qr/called at accessor Foo::baz of attribute bar \(defined at $0 line $attr_bar_line\)/,
53 "got definition context for the accessor"
63 # just dying here won't work, because perl's exception handling is
65 sub DEMOLISH { try { confess } catch { warn $_ } }
67 __PACKAGE__->meta->make_immutable;
68 $dtor_line = __LINE__ - 1;
73 local $SIG{__WARN__} = sub { $warning .= $_[0] };
77 qr/called at destructor Bar::DESTROY \(defined at $0 line $dtor_line\)/,
78 "got definition context for the destructor"