Filename | /usr/share/perl5/DBIx/Class/Exception.pm |
Statements | Executed 12 statements in 395µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 15µs | 44µs | BEGIN@14 | DBIx::Class::Exception::
1 | 1 | 1 | 12µs | 19µs | BEGIN@3 | DBIx::Class::Exception::
1 | 1 | 1 | 7µs | 7µs | BEGIN@8 | DBIx::Class::Exception::
1 | 1 | 1 | 7µs | 10µs | BEGIN@4 | DBIx::Class::Exception::
1 | 1 | 1 | 4µs | 4µs | BEGIN@11 | DBIx::Class::Exception::
0 | 0 | 0 | 0s | 0s | __ANON__[:14] | DBIx::Class::Exception::
0 | 0 | 0 | 0s | 0s | rethrow | DBIx::Class::Exception::
0 | 0 | 0 | 0s | 0s | throw | DBIx::Class::Exception::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DBIx::Class::Exception; | ||||
2 | |||||
3 | 2 | 39µs | 2 | 25µs | # spent 19µs (12+6) within DBIx::Class::Exception::BEGIN@3 which was called:
# once (12µs+6µs) by DBIx::Class::BEGIN@25 at line 3 # spent 19µs making 1 call to DBIx::Class::Exception::BEGIN@3
# spent 6µs making 1 call to strict::import |
4 | 2 | 39µs | 2 | 14µs | # spent 10µs (7+4) within DBIx::Class::Exception::BEGIN@4 which was called:
# once (7µs+4µs) by DBIx::Class::BEGIN@25 at line 4 # spent 10µs making 1 call to DBIx::Class::Exception::BEGIN@4
# spent 4µs making 1 call to warnings::import |
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 | 2 | 38µs | 1 | 7µs | # spent 7µs within DBIx::Class::Exception::BEGIN@8 which was called:
# once (7µs+0s) by DBIx::Class::BEGIN@25 at line 8 # spent 7µs making 1 call to DBIx::Class::Exception::BEGIN@8 |
9 | 1 | 1µs | $Carp::Internal{ (__PACKAGE__) }++; | ||
10 | |||||
11 | 2 | 46µs | 1 | 4µs | # spent 4µs within DBIx::Class::Exception::BEGIN@11 which was called:
# once (4µs+0s) by DBIx::Class::BEGIN@25 at line 11 # spent 4µs making 1 call to DBIx::Class::Exception::BEGIN@11 |
12 | |||||
13 | use overload | ||||
14 | # spent 44µs (15+30) within DBIx::Class::Exception::BEGIN@14 which was called:
# once (15µs+30µs) by DBIx::Class::BEGIN@25 at line 15 | ||||
15 | 2 | 231µs | 2 | 74µs | fallback => 1; # spent 44µs making 1 call to DBIx::Class::Exception::BEGIN@14
# spent 30µs making 1 call to overload::import |
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 boolean C<$stacktrace> | ||||
44 | causes it to output a full trace similar to L<confess|Carp/DESCRIPTION>. | ||||
45 | |||||
46 | DBIx::Class::Exception->throw('Foo'); | ||||
47 | try { ... } catch { DBIx::Class::Exception->throw(shift) } | ||||
48 | |||||
49 | =cut | ||||
50 | |||||
51 | sub throw { | ||||
52 | my ($class, $msg, $stacktrace) = @_; | ||||
53 | |||||
54 | # Don't re-encapsulate exception objects of any kind | ||||
55 | die $msg if ref($msg); | ||||
56 | |||||
57 | # all exceptions include a caller | ||||
58 | $msg =~ s/\n$//; | ||||
59 | |||||
60 | if(!$stacktrace) { | ||||
61 | # skip all frames that match the original caller, or any of | ||||
62 | # the dbic-wide classdata patterns | ||||
63 | my ($ln, $calling) = DBIx::Class::Carp::__find_caller( | ||||
64 | '^' . caller() . '$', | ||||
65 | 'DBIx::Class', | ||||
66 | ); | ||||
67 | |||||
68 | $msg = "${calling}${msg} ${ln}\n"; | ||||
69 | } | ||||
70 | else { | ||||
71 | $msg = Carp::longmess($msg); | ||||
72 | } | ||||
73 | |||||
74 | my $self = { msg => $msg }; | ||||
75 | bless $self => $class; | ||||
76 | |||||
77 | 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 | die shift; | ||||
89 | } | ||||
90 | |||||
91 | =head1 FURTHER QUESTIONS? | ||||
92 | |||||
93 | Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>. | ||||
94 | |||||
95 | =head1 COPYRIGHT AND LICENSE | ||||
96 | |||||
97 | This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE> | ||||
98 | by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can | ||||
99 | redistribute it and/or modify it under the same terms as the | ||||
100 | L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>. | ||||
101 | |||||
102 | =cut | ||||
103 | |||||
104 | 1 | 2µs | 1; |