File | /wise/base/static/lib/perl5/site_perl/5.10.0/DBIx/Class/Exception.pm | Statements Executed | 16 | Total Time | 0.001492 seconds |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine | |
---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | DBIx::Class::Exception:: | BEGIN |
0 | 0 | 0 | 0 | 0 | DBIx::Class::Exception:: | __ANON__[:10] |
0 | 0 | 0 | 0 | 0 | DBIx::Class::Exception:: | rethrow |
0 | 0 | 0 | 0 | 0 | DBIx::Class::Exception:: | throw |
Line | Stmts. | Exclusive Time | Avg. | Code |
---|---|---|---|---|
1 | package DBIx::Class::Exception; | |||
2 | ||||
3 | 3 | 3.2e-5 | 1.1e-5 | use strict; # spent 10µs making 1 call to strict::import |
4 | 3 | 3.5e-5 | 1.2e-5 | use warnings; # spent 32µs making 1 call to warnings::import |
5 | ||||
6 | 3 | 0.00120 | 0.00040 | use Carp::Clan qw/^DBIx::Class/; # spent 125µs making 1 call to Carp::Clan::import |
7 | 3 | 8.0e-5 | 2.7e-5 | use Scalar::Util qw/blessed/; # spent 43µs making 1 call to Exporter::import |
8 | ||||
9 | use overload | |||
10 | '""' => sub { shift->{msg} }, | |||
11 | 3 | 0.00014 | 4.6e-5 | fallback => 1; # spent 79µs making 1 call to overload::import |
12 | ||||
13 | =head1 NAME | |||
14 | ||||
15 | DBIx::Class::Exception - Exception objects for DBIx::Class | |||
16 | ||||
17 | =head1 DESCRIPTION | |||
18 | ||||
19 | Exception objects of this class are used in internally by | |||
20 | he default error handling of L<DBIx::Class::Schema/throw_exception> | |||
21 | to prevent confusing and/or redundant re-application of L<Carp>'s | |||
22 | stack trace information. | |||
23 | ||||
24 | These objects stringify to the contained error message, and use | |||
25 | overload fallback to give natural boolean/numeric values. | |||
26 | ||||
27 | =head1 METHODS | |||
28 | ||||
29 | =head2 throw | |||
30 | ||||
31 | =over 4 | |||
32 | ||||
33 | =item Arguments: $exception_scalar, $stacktrace | |||
34 | ||||
35 | =back | |||
36 | ||||
37 | This is meant for internal use by L<DBIx::Class>'s C<throw_exception> | |||
38 | code, and shouldn't be used directly elsewhere. | |||
39 | ||||
40 | Expects a scalar exception message. The optional argument | |||
41 | C<$stacktrace> tells it to use L<Carp/longmess> instead of | |||
42 | L<Carp::Clan/croak>. | |||
43 | ||||
44 | DBIx::Class::Exception->throw('Foo'); | |||
45 | eval { ... }; DBIx::Class::Exception->throw($@) if $@; | |||
46 | ||||
47 | =cut | |||
48 | ||||
49 | sub throw { | |||
50 | my ($class, $msg, $stacktrace) = @_; | |||
51 | ||||
52 | # Don't re-encapsulate exception objects of any kind | |||
53 | die $msg if blessed($msg); | |||
54 | ||||
55 | # use Carp::Clan's croak if we're not stack tracing | |||
56 | if(!$stacktrace) { | |||
57 | local $@; | |||
58 | eval { croak $msg }; | |||
59 | $msg = $@ | |||
60 | } | |||
61 | else { | |||
62 | $msg = Carp::longmess($msg); | |||
63 | } | |||
64 | ||||
65 | my $self = { msg => $msg }; | |||
66 | bless $self => $class; | |||
67 | ||||
68 | die $self; | |||
69 | } | |||
70 | ||||
71 | =head2 rethrow | |||
72 | ||||
73 | This method provides some syntactic sugar in order to | |||
74 | re-throw exceptions. | |||
75 | ||||
76 | =cut | |||
77 | ||||
78 | sub rethrow { | |||
79 | die shift; | |||
80 | } | |||
81 | ||||
82 | =head1 AUTHORS | |||
83 | ||||
84 | Brandon L. Black <blblack@gmail.com> | |||
85 | ||||
86 | =head1 LICENSE | |||
87 | ||||
88 | You may distribute this code under the same terms as Perl itself. | |||
89 | ||||
90 | =cut | |||
91 | ||||
92 | 1 | 3.0e-6 | 3.0e-6 | 1; |