enabling immutable finishing porting Log and stats
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Exception.pm
1 package Catalyst::Exception;
2
3 # XXX: See bottom of file for Exception implementation
4
5 package Catalyst::Exception::Base;
6
7 use Moose;
8 use Carp ();
9
10 =head1 NAME
11
12 Catalyst::Exception - Catalyst Exception Class
13
14 =head1 SYNOPSIS
15
16    Catalyst::Exception->throw( qq/Fatal exception/ );
17
18 See also L<Catalyst>.
19
20 =head1 DESCRIPTION
21
22 This is the Catalyst Exception class.
23
24 =head1 METHODS
25
26 =head2 throw( $message )
27
28 =head2 throw( message => $message )
29
30 =head2 throw( error => $error )
31
32 Throws a fatal exception.
33
34 =cut
35
36 sub throw {
37     my $class  = shift;
38     my %params = @_ == 1 ? ( error => $_[0] ) : @_;
39
40     my $message = $params{message} || $params{error} || $! || '';
41
42     local $Carp::CarpLevel = 1;
43
44     Carp::croak($message);
45 }
46
47 =head2 meta
48
49 Provided by Moose
50
51 =head1 AUTHOR
52
53 Sebastian Riedel, C<sri@cpan.org>
54 Christian Hansen, C<ch@ngmedia.com>
55
56 =head1 COPYRIGHT
57
58 This program is free software, you can redistribute it and/or modify
59 it under the same terms as Perl itself.
60
61 =cut
62
63 Catalyst::Exception::Base->meta->make_immutable;
64
65 package Catalyst::Exception;
66
67 use Moose;
68 use vars qw[$CATALYST_EXCEPTION_CLASS];
69
70 BEGIN {
71     extends($CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base');
72 }
73
74 Catalyst::Exception->meta->make_immutable;
75
76 1;