Commit | Line | Data |
---|---|---|
a2f2cde9 | 1 | package Catalyst::Exception; |
2 | ||
3cdcf968 | 3 | # XXX: See bottom of file for Exception implementation |
a2f2cde9 | 4 | |
5 | package Catalyst::Exception::Base; | |
6 | ||
3cdcf968 | 7 | use Moose; |
a80247cf | 8 | use Carp; |
9 | use namespace::clean -except => 'meta'; | |
a2f2cde9 | 10 | |
11 | =head1 NAME | |
12 | ||
13 | Catalyst::Exception - Catalyst Exception Class | |
14 | ||
15 | =head1 SYNOPSIS | |
16 | ||
17 | Catalyst::Exception->throw( qq/Fatal exception/ ); | |
18 | ||
19 | See also L<Catalyst>. | |
20 | ||
21 | =head1 DESCRIPTION | |
22 | ||
23 | This is the Catalyst Exception class. | |
24 | ||
25 | =head1 METHODS | |
26 | ||
b5ecfcf0 | 27 | =head2 throw( $message ) |
a2f2cde9 | 28 | |
b5ecfcf0 | 29 | =head2 throw( message => $message ) |
ebfde331 | 30 | |
b5ecfcf0 | 31 | =head2 throw( error => $error ) |
a2f2cde9 | 32 | |
33 | Throws a fatal exception. | |
34 | ||
35 | =cut | |
36 | ||
9ffa230b | 37 | has message => ( |
38 | is => 'ro', | |
39 | isa => 'Str', | |
40 | ); | |
41 | ||
ccf2a6da | 42 | use overload |
43 | q{""} => \&as_string, | |
44 | fallback => 1; | |
0af1b40c | 45 | |
46 | sub as_string { | |
47 | my ($self) = @_; | |
48 | return $self->message; | |
49 | } | |
50 | ||
a2f2cde9 | 51 | sub throw { |
52 | my $class = shift; | |
53 | my %params = @_ == 1 ? ( error => $_[0] ) : @_; | |
54 | ||
6054110c | 55 | $params{message} = $params{message} || $params{error} || $! || ''; |
56 | my $error = $class->new(%params); | |
a2f2cde9 | 57 | |
58 | local $Carp::CarpLevel = 1; | |
59 | ||
6054110c | 60 | croak($error); |
a2f2cde9 | 61 | } |
62 | ||
3cdcf968 | 63 | =head2 meta |
64 | ||
65 | Provided by Moose | |
66 | ||
2f381252 | 67 | =head1 AUTHORS |
a2f2cde9 | 68 | |
2f381252 | 69 | Catalyst Contributors, see Catalyst.pm |
a2f2cde9 | 70 | |
71 | =head1 COPYRIGHT | |
72 | ||
536bee89 | 73 | This library is free software. You can redistribute it and/or modify |
a2f2cde9 | 74 | it under the same terms as Perl itself. |
75 | ||
76 | =cut | |
77 | ||
e5ecd5bc | 78 | Catalyst::Exception::Base->meta->make_immutable; |
79 | ||
3cdcf968 | 80 | package Catalyst::Exception; |
81 | ||
82 | use Moose; | |
a80247cf | 83 | use namespace::clean -except => 'meta'; |
84 | ||
3cdcf968 | 85 | use vars qw[$CATALYST_EXCEPTION_CLASS]; |
86 | ||
87 | BEGIN { | |
88 | extends($CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base'); | |
89 | } | |
90 | ||
6680c772 | 91 | __PACKAGE__->meta->make_immutable; |
e5ecd5bc | 92 | |
a2f2cde9 | 93 | 1; |