Commit | Line | Data |
78bab9ca |
1 | package DBIx::Class::Exception; |
2 | |
3 | use strict; |
4 | use vars qw[@ISA $DBIC_EXCEPTION_CLASS]; |
5 | use UNIVERSAL::require; |
6 | |
7 | BEGIN { |
8 | push( @ISA, $DBIC_EXCEPTION_CLASS || 'DBIx::Class::Exception::Base' ); |
9 | } |
10 | |
11 | package DBIx::Class::Exception::Base; |
12 | |
13 | use strict; |
14 | use Carp (); |
15 | |
16 | =head1 NAME |
17 | |
18 | DBIx::Class::Exception - DBIC Exception Class |
19 | |
20 | =head1 SYNOPSIS |
21 | |
22 | DBIx::Class::Exception->throw( qq/Fatal exception/ ); |
23 | |
24 | See also L<DBIx::Class>. |
25 | |
26 | =head1 DESCRIPTION |
27 | |
28 | This is a generic Exception class for DBIx::Class. You can easily |
29 | replace this with any mechanism implementing 'throw' by setting |
30 | $DBix::Class::Exception::DBIC_EXCEPTION_CLASS |
31 | |
32 | =head1 METHODS |
33 | |
8091aa91 |
34 | =head2 throw( $message ) |
78bab9ca |
35 | |
8091aa91 |
36 | =head2 throw( message => $message ) |
78bab9ca |
37 | |
8091aa91 |
38 | =head2 throw( error => $error ) |
78bab9ca |
39 | |
40 | Throws a fatal exception. |
41 | |
42 | =cut |
43 | |
44 | sub throw { |
45 | my $class = shift; |
46 | my %params = @_ == 1 ? ( error => $_[0] ) : @_; |
47 | |
48 | my $message = $params{message} || $params{error} || $! || ''; |
49 | |
07037f89 |
50 | local $Carp::CarpLevel = (caller(1) eq 'NEXT' ? 2 : 1); |
78bab9ca |
51 | |
52 | Carp::croak($message); |
53 | } |
54 | |
78bab9ca |
55 | =head1 AUTHOR |
56 | |
57 | Marcus Ramberg <mramberg@cpan.org> |
58 | |
59 | =head1 THANKS |
60 | |
61 | Thanks to the L<Catalyst> framework, where this module was borrowed |
62 | from. |
63 | |
64 | =head1 COPYRIGHT |
65 | |
66 | This program is free software, you can redistribute it and/or modify |
67 | it under the same terms as Perl itself. |
68 | |
69 | =cut |
70 | |
71 | 1; |