Teach Cat to pass a _component_name into COMPONENT method, which is what ends up...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Exception.pm
CommitLineData
a2f2cde9 1package Catalyst::Exception;
2
3cdcf968 3# XXX: See bottom of file for Exception implementation
a2f2cde9 4
5package Catalyst::Exception::Base;
6
3cdcf968 7use Moose;
a80247cf 8use Carp;
9use namespace::clean -except => 'meta';
a2f2cde9 10
11=head1 NAME
12
13Catalyst::Exception - Catalyst Exception Class
14
15=head1 SYNOPSIS
16
17 Catalyst::Exception->throw( qq/Fatal exception/ );
18
19See also L<Catalyst>.
20
21=head1 DESCRIPTION
22
23This 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
33Throws a fatal exception.
34
35=cut
36
9ffa230b 37has message => (
62ef37bf 38 is => 'ro',
39 isa => 'Str',
40 default => sub { $! || '' },
9ffa230b 41);
42
ccf2a6da 43use overload
44 q{""} => \&as_string,
45 fallback => 1;
0af1b40c 46
47sub as_string {
48 my ($self) = @_;
49 return $self->message;
50}
51
62ef37bf 52around BUILDARGS => sub {
53 my ($next, $class, @args) = @_;
54 if (@args == 1 && !ref $args[0]) {
55 @args = (message => $args[0]);
56 }
a2f2cde9 57
62ef37bf 58 my $args = $class->$next(@args);
59 $args->{message} ||= $args->{error}
60 if exists $args->{error};
a2f2cde9 61
62ef37bf 62 return $args;
63};
a2f2cde9 64
62ef37bf 65sub throw {
66 my $class = shift;
67 my $error = $class->new(@_);
68 local $Carp::CarpLevel = 1;
44b74e6a 69 croak $error;
70}
71
72sub rethrow {
73 my ($self) = @_;
74 croak $self;
a2f2cde9 75}
76
3cdcf968 77=head2 meta
78
79Provided by Moose
80
2f381252 81=head1 AUTHORS
a2f2cde9 82
2f381252 83Catalyst Contributors, see Catalyst.pm
a2f2cde9 84
85=head1 COPYRIGHT
86
536bee89 87This library is free software. You can redistribute it and/or modify
a2f2cde9 88it under the same terms as Perl itself.
89
90=cut
91
e5ecd5bc 92Catalyst::Exception::Base->meta->make_immutable;
93
3cdcf968 94package Catalyst::Exception;
95
96use Moose;
a80247cf 97use namespace::clean -except => 'meta';
98
3cdcf968 99use vars qw[$CATALYST_EXCEPTION_CLASS];
100
101BEGIN {
102 extends($CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base');
103}
104
6680c772 105__PACKAGE__->meta->make_immutable;
e5ecd5bc 106
a2f2cde9 1071;