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.06'; |
4
|
4
|
|
|
4
|
|
144303
|
use strict; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
111
|
|
5
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
92
|
|
6
|
4
|
|
|
4
|
|
16
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
200
|
|
7
|
4
|
|
|
4
|
|
1004
|
use Class::Load 'load_class'; |
|
4
|
|
|
|
|
48998
|
|
|
4
|
|
|
|
|
214
|
|
8
|
4
|
|
|
4
|
|
2521
|
use Data::Dump::Streamer; |
|
4
|
|
|
|
|
158330
|
|
|
4
|
|
|
|
|
26
|
|
9
|
4
|
|
|
4
|
|
1732
|
use MIME::Base64; |
|
4
|
|
|
|
|
2012
|
|
|
4
|
|
|
|
|
227
|
|
10
|
4
|
|
|
4
|
|
888
|
use Try::Catch; |
|
4
|
|
|
|
|
2485
|
|
|
4
|
|
|
|
|
201
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
27
|
use constant READY => 1; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
265
|
|
13
|
4
|
|
|
4
|
|
20
|
use constant DONE => 2; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
156
|
|
14
|
4
|
|
|
4
|
|
20
|
use constant FAIL => 4; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1409
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
34
|
|
|
34
|
0
|
12041
|
my ($class, $code, $args) = @_; |
18
|
34
|
|
|
|
|
208
|
bless [READY, [$code, $args]], $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
7
|
|
|
7
|
0
|
1820
|
sub done { $_[0][0] & DONE } |
22
|
30
|
|
|
30
|
0
|
155
|
sub failed { $_[0][0] & FAIL } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub result { |
25
|
32
|
50
|
|
32
|
0
|
334
|
return $_[0][1] if $_[0][0] & DONE; |
26
|
0
|
|
|
|
|
0
|
return; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub execute { |
30
|
4
|
|
|
4
|
0
|
8
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
try { |
33
|
4
|
|
|
4
|
|
100
|
my ($work, $args) = @{$self->[1]}; |
|
4
|
|
|
|
|
11
|
|
34
|
|
|
|
|
|
|
|
35
|
4
|
100
|
|
|
|
11
|
if (ref $work eq 'CODE') { |
36
|
3
|
|
|
|
|
7
|
$self->[1] = $work->(@$args); |
37
|
2
|
|
|
|
|
11
|
$self->[0] = DONE; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
1
|
|
|
|
|
6
|
my $class = load_class($work); |
41
|
1
|
|
|
|
|
439
|
$self->[1] = $class->new(@$args)->run; |
42
|
1
|
|
|
|
|
11
|
$self->[0] = DONE; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
catch { |
46
|
1
|
|
|
1
|
|
18
|
$self->[0] = DONE | FAIL; |
47
|
1
|
|
|
|
|
3
|
$self->[1] = $_; |
48
|
4
|
|
|
|
|
32
|
}; |
49
|
|
|
|
|
|
|
|
50
|
4
|
100
|
|
|
|
68
|
return $self->[0] & FAIL ? 0 : 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub encode { |
54
|
31
|
|
|
31
|
0
|
82
|
my $self = shift; |
55
|
31
|
|
|
|
|
239
|
my $data = Dump($self)->Purity(1)->Declare(1)->Indent(0)->Out; |
56
|
31
|
|
|
|
|
134554
|
encode_base64($data, ''); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub decode { |
60
|
31
|
|
|
31
|
0
|
588
|
my $class = shift; |
61
|
31
|
|
|
|
|
241
|
my $data = decode_base64($_[0]); |
62
|
31
|
|
|
|
|
3214
|
my $self = eval "do{ $data }"; |
63
|
31
|
50
|
|
|
|
207
|
croak "task decode error: $@" if $@; |
64
|
31
|
|
|
|
|
135
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |