line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Preproc::Exception; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# SQL::Preproc::Exception - runtime exception handler module for SQL::Preproc |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Provides a container object for SQL::Preproc context and exception |
6
|
|
|
|
|
|
|
# handling. When this object goes out of scope, the DESTROY method |
7
|
|
|
|
|
|
|
# will remove it from the sqlpp_ctxt exception stack |
8
|
|
|
|
|
|
|
# |
9
|
7
|
|
|
7
|
|
43
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
2347
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
14
|
|
|
14
|
0
|
37
|
my ($class, $ctxt, $handler) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
return undef |
16
|
14
|
50
|
33
|
|
|
166
|
unless (defined($handler) && |
|
|
|
33
|
|
|
|
|
17
|
|
|
|
|
|
|
(ref $handler) && |
18
|
|
|
|
|
|
|
(ref $handler eq 'CODE')); |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# use arrayref to save memory/runtime |
21
|
|
|
|
|
|
|
# |
22
|
14
|
|
|
|
|
36
|
my $obj = [ $ctxt, $handler ]; |
23
|
14
|
|
|
|
|
39
|
bless $obj, $class; |
24
|
14
|
|
|
|
|
50
|
return $obj; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub catch { |
28
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
# make sure that any exceptions thrown within the |
31
|
|
|
|
|
|
|
# handler are caught by the default handlers |
32
|
|
|
|
|
|
|
# |
33
|
0
|
|
|
|
|
|
my $old_handler = $obj->[0]{handler_idx}; |
34
|
0
|
|
|
|
|
|
$obj->[0]{handler_idx} = 0; |
35
|
0
|
0
|
0
|
|
|
|
if (defined($_[1]) && ref $_[1]) { |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# shortcut: we've got a handle, so grab info from it |
38
|
|
|
|
|
|
|
# |
39
|
0
|
|
|
|
|
|
my $h = $_[1]; |
40
|
0
|
|
|
|
|
|
$obj->[1]->($_[0], $h->err, $h->state, $h->errstr); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
0
|
|
|
|
|
|
$obj->[1]->(@_); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
$obj->[0]{handler_idx} = $old_handler; |
46
|
0
|
|
|
|
|
|
return 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub raise { |
50
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# make sure that any exceptions thrown within the |
53
|
|
|
|
|
|
|
# handler are caught by the default handlers |
54
|
|
|
|
|
|
|
# |
55
|
0
|
|
|
|
|
|
my $old_handler = $obj->[0]{handler_idx}; |
56
|
0
|
|
|
|
|
|
$obj->[0]{handler_idx} = 0; |
57
|
0
|
|
|
|
|
|
$obj->[1]->(@_); |
58
|
0
|
|
|
|
|
|
$obj->[0]{handler_idx} = $old_handler; |
59
|
0
|
|
|
|
|
|
return 1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |