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_001'; # TRIAL |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
143334
|
$AnyEvent::ProcessPool::Task::VERSION = '0.06001';use common::sense; |
|
4
|
|
|
|
|
28
|
|
|
4
|
|
|
|
|
28
|
|
6
|
4
|
|
|
4
|
|
191
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
186
|
|
7
|
4
|
|
|
4
|
|
990
|
use Class::Load 'load_class'; |
|
4
|
|
|
|
|
43330
|
|
|
4
|
|
|
|
|
220
|
|
8
|
4
|
|
|
4
|
|
2240
|
use Data::Dump::Streamer; |
|
4
|
|
|
|
|
173891
|
|
|
4
|
|
|
|
|
28
|
|
9
|
4
|
|
|
4
|
|
1634
|
use MIME::Base64; |
|
4
|
|
|
|
|
1967
|
|
|
4
|
|
|
|
|
219
|
|
10
|
4
|
|
|
4
|
|
886
|
use Try::Catch; |
|
4
|
|
|
|
|
2538
|
|
|
4
|
|
|
|
|
203
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
24
|
use constant READY => 1; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
244
|
|
13
|
4
|
|
|
4
|
|
20
|
use constant DONE => 2; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
153
|
|
14
|
4
|
|
|
4
|
|
30
|
use constant FAIL => 4; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1787
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
42
|
|
|
42
|
0
|
10722
|
my ($class, $code, $args) = @_; |
18
|
42
|
|
|
|
|
244
|
bless [READY, [$code, $args]], $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
5
|
0
|
610
|
sub done { $_[0][0] & DONE } |
22
|
28
|
|
|
28
|
0
|
98
|
sub failed { $_[0][0] & FAIL } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub result { |
25
|
39
|
50
|
|
39
|
0
|
452
|
return $_[0][1] if $_[0][0] & DONE; |
26
|
0
|
|
|
|
|
0
|
return; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub execute { |
30
|
4
|
|
|
4
|
0
|
20
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
try { |
33
|
4
|
|
|
4
|
|
77
|
my ($work, $args) = @{$self->[1]}; |
|
4
|
|
|
|
|
8
|
|
34
|
|
|
|
|
|
|
|
35
|
4
|
100
|
|
|
|
16
|
if (ref $work eq 'CODE') { |
36
|
3
|
|
|
|
|
7
|
$self->[1] = $work->(@$args); |
37
|
2
|
|
|
|
|
11
|
$self->[0] = DONE; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
1
|
|
|
|
|
3
|
my $class = load_class($work); |
41
|
1
|
|
|
|
|
467
|
$self->[1] = $class->new(@$args)->run; |
42
|
1
|
|
|
|
|
11
|
$self->[0] = DONE; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
catch { |
46
|
1
|
|
|
1
|
|
16
|
$self->[0] = DONE | FAIL; |
47
|
1
|
|
|
|
|
3
|
$self->[1] = $_; |
48
|
4
|
|
|
|
|
25
|
}; |
49
|
|
|
|
|
|
|
|
50
|
4
|
100
|
|
|
|
65
|
return $self->[0] & FAIL ? 0 : 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub encode { |
54
|
39
|
|
|
39
|
0
|
122
|
my $self = shift; |
55
|
39
|
|
|
|
|
395
|
my $data = DumpLex($self)->Purity(1)->Declare(1)->Indent(0)->Out; |
56
|
39
|
|
|
|
|
154596
|
encode_base64($data, ''); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub decode { |
60
|
39
|
|
|
39
|
0
|
527
|
my $class = shift; |
61
|
39
|
|
|
|
|
133
|
my $data = decode_base64($_[0]); |
62
|
39
|
|
|
|
|
3342
|
my $self = eval "do{ $data }"; |
63
|
39
|
50
|
|
|
|
239
|
croak "task decode error: $@" if $@; |
64
|
39
|
|
|
|
|
116
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |