DBIx/Class/Exception.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 95.3% 41 / 43 CC 3 SCAR 4.7
CC
3
Cov
94%
throw
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« DBIx/Class.pm ↑ Summary DBIx/Class/SQLMaker/Oracle.pm »
1 package DBIx::Class::Exception;
2  
3 308 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 308 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # load Carp early to prevent tickling of the ::Internal stash being
7 # interpreted as "Carp is already loaded" by some braindead loader
8 308 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 308 $Carp::Internal{ (__PACKAGE__) }++;
10  
11 308 ▶use DBIx::Class::Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 use overload
14 1206 ▶ '""' => sub { shift->{msg} },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 308 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 DBIx::Class::Exception - Exception objects for DBIx::Class
20  
21 =head1 DESCRIPTION
22  
23 Exception objects of this class are used internally by
24 the default error handling of L<DBIx::Class::Schema/throw_exception>
25 and derivatives.
26  
27 These objects stringify to the contained error message, and use
28 overload fallback to give natural boolean/numeric values.
29  
30 =head1 METHODS
31  
32 =head2 throw
33  
34 =over 4
35  
36 =item Arguments: $exception_scalar, $stacktrace
37  
38 =back
39  
40 This is meant for internal use by L<DBIx::Class>'s C<throw_exception>
41 code, and shouldn't be used directly elsewhere.
42  
43 Expects a scalar exception message. The optional argument
44 C<$stacktrace> tells it to output a full trace similar to L<Carp/confess>.
45  
46 DBIx::Class::Exception->throw('Foo');
47 try { ... } catch { DBIx::Class::Exception->throw(shift) }
48  
49 =cut
50  
51 sub throw {
52 2646 ▶ my ($class, $msg, $stacktrace) = @_;
Subroutine throw: called CC=3 SCAR=11.1
Pod documented
53  
54 # Don't re-encapsulate exception objects of any kind
55 2646 ▶ die $msg if ref($msg);
Branch: 1 branch
BranchTrueFalseTotal
if ref $msg 24 2622 2646
56  
57 # all exceptions include a caller
58 2622 $msg =~ s/\n$//;
59  
60 2622 ▶ if(!$stacktrace) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $stacktrace) { } 2622 0 2622
61 # skip all frames that match the original caller, or any of
62 # the dbic-wide classdata patterns
63 2622 my ($ln, $calling) = DBIx::Class::Carp::__find_caller(
64 '^' . caller() . '$',
65 'DBIx::Class',
66 );
67  
68 2622 $msg = "${calling}${msg} ${ln}\n";
69 }
70 else {
71 0 $msg = Carp::longmess($msg);
72 }
73  
74 2622 my $self = { msg => $msg };
75 2622 bless $self => $class;
76  
77 2622 die $self;
78 }
79  
80 =head2 rethrow
81  
82 This method provides some syntactic sugar in order to
83 re-throw exceptions.
84  
85 =cut
86  
87 sub rethrow {
88 1 ▶ die shift;
Subroutine rethrow: called CC=1 SCAR=0.0
Pod documented
89 }
90  
91 =head1 AUTHOR AND CONTRIBUTORS
92  
93 See L<AUTHOR|DBIx::Class/AUTHOR> and L<CONTRIBUTORS|DBIx::Class/CONTRIBUTORS> in DBIx::Class
94  
95 =head1 LICENSE
96  
97 You may distribute this code under the same terms as Perl itself.
98  
99 =cut
100  
101 308 1;
« DBIx/Class.pm ↑ Summary DBIx/Class/SQLMaker/Oracle.pm »