line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::ProcessPool::Task; |
2
|
|
|
|
|
|
|
# ABSTRACT: A serializable work unit |
3
|
|
|
|
|
|
|
$AnyEvent::ProcessPool::Task::VERSION = '0.07'; |
4
|
4
|
|
|
4
|
|
171834
|
use common::sense; |
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
22
|
|
5
|
4
|
|
|
4
|
|
188
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
179
|
|
6
|
4
|
|
|
4
|
|
1475
|
use Class::Load 'load_class'; |
|
4
|
|
|
|
|
55965
|
|
|
4
|
|
|
|
|
190
|
|
7
|
4
|
|
|
4
|
|
2778
|
use Data::Dump::Streamer; |
|
4
|
|
|
|
|
174049
|
|
|
4
|
|
|
|
|
23
|
|
8
|
4
|
|
|
4
|
|
1884
|
use MIME::Base64; |
|
4
|
|
|
|
|
1865
|
|
|
4
|
|
|
|
|
192
|
|
9
|
4
|
|
|
4
|
|
1333
|
use Try::Catch; |
|
4
|
|
|
|
|
2400
|
|
|
4
|
|
|
|
|
184
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
23
|
use constant READY => 1; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
229
|
|
12
|
4
|
|
|
4
|
|
18
|
use constant DONE => 2; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
148
|
|
13
|
4
|
|
|
4
|
|
17
|
use constant FAIL => 4; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1918
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
34
|
|
|
34
|
0
|
13473
|
my ($class, $code, $args) = @_; |
17
|
34
|
|
|
|
|
259
|
bless [READY, [$code, $args]], $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
7
|
|
|
7
|
0
|
2098
|
sub done { $_[0][0] & DONE } |
21
|
30
|
|
|
30
|
0
|
137
|
sub failed { $_[0][0] & FAIL } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub result { |
24
|
32
|
50
|
|
32
|
0
|
296
|
return $_[0][1] if $_[0][0] & DONE; |
25
|
0
|
|
|
|
|
0
|
return; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub execute { |
29
|
4
|
|
|
4
|
0
|
7
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
try { |
32
|
4
|
|
|
4
|
|
81
|
my ($work, $args) = @{$self->[1]}; |
|
4
|
|
|
|
|
11
|
|
33
|
|
|
|
|
|
|
|
34
|
4
|
100
|
|
|
|
18
|
if (ref $work eq 'CODE') { |
35
|
3
|
|
|
|
|
13
|
$self->[1] = $work->(@$args); |
36
|
2
|
|
|
|
|
11
|
$self->[0] = DONE; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
1
|
|
|
|
|
7
|
my $class = load_class($work); |
40
|
1
|
|
|
|
|
532
|
$self->[1] = $class->new(@$args)->run; |
41
|
1
|
|
|
|
|
11
|
$self->[0] = DONE; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
catch { |
45
|
1
|
|
|
1
|
|
17
|
$self->[0] = DONE | FAIL; |
46
|
1
|
|
|
|
|
2
|
$self->[1] = $_; |
47
|
4
|
|
|
|
|
39
|
}; |
48
|
|
|
|
|
|
|
|
49
|
4
|
100
|
|
|
|
74
|
return $self->[0] & FAIL ? 0 : 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub encode { |
53
|
31
|
|
|
31
|
0
|
124
|
my $self = shift; |
54
|
31
|
|
|
|
|
351
|
my $data = DumpLex($self)->Purity(1)->Declare(1)->Indent(0)->Out; |
55
|
31
|
|
|
|
|
135262
|
encode_base64($data, ''); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub decode { |
59
|
31
|
|
|
31
|
0
|
638
|
my $class = shift; |
60
|
31
|
|
|
|
|
231
|
my $data = decode_base64($_[0]); |
61
|
31
|
|
|
|
|
3845
|
my $self = eval "do{ $data }"; |
62
|
31
|
50
|
|
|
|
259
|
croak "task decode error: $@" if $@; |
63
|
31
|
|
|
|
|
119
|
return $self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |