line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Exception::Resumable; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Exception::Resumable -- resumable exceptions for Perl. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Exception::Resumable; |
10
|
|
|
|
|
|
|
handle { |
11
|
|
|
|
|
|
|
... |
12
|
|
|
|
|
|
|
raise $exception, @args; |
13
|
|
|
|
|
|
|
... |
14
|
|
|
|
|
|
|
} exception_1 => sub { ...; return $value_to_use }, |
15
|
|
|
|
|
|
|
qr/exception_2/ => sub { ...; raise $new_exception, @args }, |
16
|
|
|
|
|
|
|
[qw(exception_3 exception_4)] => $value_to_use, |
17
|
|
|
|
|
|
|
{ exception_5 => 1, exception_6 => 1 } => sub { ... }; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$VERSION = '0.91'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
require Exporter; |
24
|
|
|
|
|
|
|
@ISA = 'Exporter'; |
25
|
|
|
|
|
|
|
@EXPORT = qw(handle raise); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub handle(&@) |
28
|
|
|
|
|
|
|
{ |
29
|
2
|
|
|
2
|
1
|
441
|
my $body = shift; |
30
|
2
|
|
|
|
|
6
|
local @LAST_CATCH = @CATCH; |
31
|
2
|
|
|
|
|
8
|
local @CATCH = (@_, @CATCH); |
32
|
2
|
|
|
|
|
4
|
local (@_); |
33
|
2
|
50
|
|
|
|
5
|
if (wantarray) { |
34
|
0
|
|
|
|
|
0
|
my @ret = eval { $body->() }; |
|
0
|
|
|
|
|
0
|
|
35
|
0
|
0
|
|
|
|
0
|
if ($@) { |
36
|
0
|
0
|
|
|
|
0
|
raise(ref($@) eq 'ARRAY' ? @{$@} : $@); |
|
0
|
|
|
|
|
0
|
|
37
|
|
|
|
|
|
|
} else { |
38
|
0
|
|
|
|
|
0
|
@ret; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} else { |
41
|
2
|
|
|
|
|
3
|
my $ret = eval { $body->() }; |
|
2
|
|
|
|
|
5
|
|
42
|
2
|
50
|
|
|
|
11
|
if ($@) { |
43
|
2
|
50
|
|
|
|
47
|
raise(ref($@) eq 'ARRAY' ? @{$@} : $@); |
|
0
|
|
|
|
|
0
|
|
44
|
|
|
|
|
|
|
} else { |
45
|
0
|
|
|
|
|
0
|
$ret; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $test; |
51
|
|
|
|
|
|
|
if ($] < 5.010) { |
52
|
|
|
|
|
|
|
$test = <<'EOS'; |
53
|
|
|
|
|
|
|
(ref $k eq 'CODE') |
54
|
|
|
|
|
|
|
? $k->($err) |
55
|
|
|
|
|
|
|
: (ref $k eq 'Regexp') |
56
|
|
|
|
|
|
|
? $err =~ /$k/ |
57
|
|
|
|
|
|
|
: (ref $k eq 'ARRAY') |
58
|
|
|
|
|
|
|
? grep { $_ eq $err } @$k |
59
|
|
|
|
|
|
|
: (ref $k eq 'HASH') |
60
|
|
|
|
|
|
|
? exists $k->{$err} |
61
|
|
|
|
|
|
|
: $k eq $err |
62
|
|
|
|
|
|
|
EOS |
63
|
|
|
|
|
|
|
} else { |
64
|
|
|
|
|
|
|
$test = '$err ~~ $k'; |
65
|
|
|
|
|
|
|
} |
66
|
8
|
100
|
|
8
|
1
|
2081
|
eval q# |
|
8
|
100
|
|
0
|
1
|
23
|
|
|
8
|
0
|
|
|
|
33
|
|
|
8
|
|
|
|
|
18
|
|
|
26
|
|
|
|
|
35
|
|
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
106
|
|
|
3
|
|
|
|
|
27
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub raise(*@) |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
my $err = shift; |
70
|
|
|
|
|
|
|
my @c = @CATCH; |
71
|
|
|
|
|
|
|
local @CATCH = @LAST_CATCH; |
72
|
|
|
|
|
|
|
while (@c) { |
73
|
|
|
|
|
|
|
my ($k, $v) = splice @c, 0, 2; |
74
|
|
|
|
|
|
|
my $ok = # . $test . q#; |
75
|
|
|
|
|
|
|
return ref($v) eq 'CODE' ? $v->(@_) : $v if $ok; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
die $err, @_; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub test_raise(*) |
81
|
|
|
|
|
|
|
{ |
82
|
|
|
|
|
|
|
my $err = shift; |
83
|
|
|
|
|
|
|
my @c = @CATCH; |
84
|
|
|
|
|
|
|
local @CATCH = @LAST_CATCH; |
85
|
|
|
|
|
|
|
while (@c) { |
86
|
|
|
|
|
|
|
my ($k, $v) = splice @c, 0, 2; |
87
|
|
|
|
|
|
|
my $ok = # . $test . q#; |
88
|
|
|
|
|
|
|
return $k, $v if $ok; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
return undef; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
#; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |