Merge branch 'abort-chain-doc-and-test' of https://github.com/melmothx/catalyst-runti...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Exception / Interface.pm
1 package Catalyst::Exception::Interface;
2
3 use Moose::Role;
4 use if !eval { require Moose; Moose->VERSION('2.1300') },
5     'MooseX::Role::WithOverloading';
6 use namespace::clean -except => 'meta';
7
8 use overload
9     q{""}    => sub { $_[0]->as_string },
10     fallback => 1;
11
12 requires qw/as_string throw rethrow/;
13
14 1;
15
16 __END__
17
18 =head1 NAME
19
20 Catalyst::Exception::Interface - Role defining the interface for Catalyst exceptions
21
22 =head1 SYNOPSIS
23
24    package My::Catalyst::Like::Exception;
25    use Moose;
26    use namespace::clean -except => 'meta';
27
28    with 'Catalyst::Exception::Interface';
29
30    # This comprises the required interface.
31    sub as_string { 'the exception text for stringification' }
32    sub throw { shift; die @_ }
33    sub rethrow { shift; die @_ }
34
35 =head1 DESCRIPTION
36
37 This is a role for the required interface for Catalyst exceptions.
38
39 It ensures that all exceptions follow the expected interface,
40 and adds overloading for stringification when composed onto a
41 class.
42
43 Note that if you compose this role onto another role, that role
44 must use L<MooseX::Role::WithOverloading>.
45
46 =head1 REQUIRED METHODS
47
48 =head2 as_string
49
50 =head2 throw
51
52 =head2 rethrow
53
54 =head1 METHODS
55
56 =head2 meta
57
58 Provided by Moose
59
60 =head1 SEE ALSO
61
62 =over 4
63
64 =item L<Catalyst>
65
66 =item L<Catalyst::Exception>
67
68 =back
69
70 =head1 AUTHORS
71
72 Catalyst Contributors, see Catalyst.pm
73
74 =head1 COPYRIGHT
75
76 This library is free software. You can redistribute it and/or modify
77 it under the same terms as Perl itself.
78
79 =cut