line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Exception::Delayed; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Execute code and throw exceptions later |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
53581
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
118
|
|
6
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
896
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub wantscalar { |
11
|
3
|
|
|
3
|
1
|
29
|
my ( $class, $code, @args ) = @_; |
12
|
3
|
|
|
|
|
5
|
my $RV; |
13
|
3
|
|
|
|
|
4
|
eval { $RV = scalar $code->(@args); }; |
|
3
|
|
|
|
|
10
|
|
14
|
3
|
100
|
|
|
|
27
|
if ($@) { |
15
|
1
|
|
|
|
|
5
|
return bless { error => $@ } => $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
else { |
18
|
2
|
|
|
|
|
12
|
return bless { result => \$RV } => $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub wantlist { |
23
|
2
|
|
|
2
|
1
|
14
|
my ( $class, $code, @args ) = @_; |
24
|
2
|
|
|
|
|
2
|
my @RV; |
25
|
2
|
|
|
|
|
4
|
eval { @RV = $code->(@args); }; |
|
2
|
|
|
|
|
5
|
|
26
|
2
|
50
|
|
|
|
18
|
if ($@) { |
27
|
0
|
|
|
|
|
0
|
return bless { error => $@ } => $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
2
|
|
|
|
|
10
|
return bless { result => \@RV } => $class; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub wantany { |
35
|
2
|
|
|
2
|
1
|
1695
|
my ( $class, $wantarray, $code, @args ) = @_; |
36
|
2
|
100
|
|
|
|
6
|
if ($wantarray) { |
37
|
1
|
|
|
|
|
4
|
return $class->wantlist( $code, @args ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
1
|
|
|
|
|
4
|
return $class->wantscalar( $code, @args ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub result { |
45
|
5
|
|
|
5
|
1
|
1619
|
my ($self) = @_; |
46
|
5
|
100
|
|
|
|
27
|
if ( exists $self->{error} ) { |
47
|
1
|
|
|
|
|
4
|
die $self->{error}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
4
|
|
|
|
|
9
|
my $result = delete $self->{result}; |
51
|
4
|
100
|
|
|
|
14
|
if ( ref $result eq 'ARRAY' ) { |
|
|
50
|
|
|
|
|
|
52
|
2
|
|
|
|
|
7
|
return @$result; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ( ref $result eq 'SCALAR' ) { |
55
|
2
|
|
|
|
|
4
|
return $$result; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |