line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Job::Async::Job; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
17
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
81
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.003'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Job::Async::Job - represents a single job for L |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
866
|
use Sereal; |
|
2
|
|
|
|
|
1802
|
|
|
2
|
|
|
|
|
93
|
|
19
|
2
|
|
|
2
|
|
862
|
use JSON::MaybeUTF8 qw(:v1); |
|
2
|
|
|
|
|
8589
|
|
|
2
|
|
|
|
|
253
|
|
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
20
|
use constant SEREAL_DEFAULT => 1; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1093
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $sereal_encode = Sereal::Encoder->new; |
24
|
|
|
|
|
|
|
my $sereal_decode = Sereal::Decoder->new; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
0
|
0
|
sub id { shift->{id} } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub data { |
29
|
5064
|
|
|
5064
|
0
|
7978
|
my ($self, $key) = @_; |
30
|
5064
|
50
|
|
|
|
8375
|
return $self->{data} unless defined $key; |
31
|
5064
|
|
|
|
|
11400
|
return $self->{data}{$key}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub flattened_data { |
35
|
0
|
|
|
0
|
0
|
0
|
my ($self, $data) = @_; |
36
|
0
|
|
0
|
|
|
0
|
$data //= $self->{data}; |
37
|
|
|
|
|
|
|
return { map { |
38
|
0
|
|
|
|
|
0
|
!ref($data->{$_}) |
39
|
|
|
|
|
|
|
? ("text_$_" => $data->{$_}) |
40
|
|
|
|
|
|
|
: SEREAL_DEFAULT |
41
|
|
|
|
|
|
|
? ("sereal_$_" => $sereal_encode->encode($data->{$_})) |
42
|
0
|
0
|
|
|
|
0
|
: ("json_$_" => encode_json_utf8($data->{$_})) |
43
|
|
|
|
|
|
|
} keys %$data }; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub structured_data { |
47
|
0
|
|
|
0
|
0
|
0
|
my ($self, $data) = @_; |
48
|
0
|
|
0
|
|
|
0
|
$data //= $self->{data}; |
49
|
|
|
|
|
|
|
return { |
50
|
|
|
|
|
|
|
(map { |
51
|
0
|
0
|
|
|
|
0
|
die "invalid format for $_" unless my ($type, $k) = /^(json|text|sereal)_(.*)$/; |
52
|
|
|
|
|
|
|
$k => ( |
53
|
|
|
|
|
|
|
$type eq 'text' |
54
|
|
|
|
|
|
|
? $data->{$_} |
55
|
|
|
|
|
|
|
: $type eq 'json' |
56
|
|
|
|
|
|
|
? decode_json_utf8($data->{$_}) |
57
|
0
|
0
|
|
|
|
0
|
: $sereal_decode->decode($data->{$_}) |
|
|
0
|
|
|
|
|
|
58
|
|
|
|
|
|
|
) |
59
|
|
|
|
|
|
|
} grep /^[a-z]/, keys %$data), |
60
|
0
|
|
|
|
|
0
|
map {; $_ => $data->{$_} } grep /^_/, keys %$data |
|
0
|
|
|
|
|
0
|
|
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
5069
|
|
|
5069
|
0
|
14852
|
sub future { shift->{future} } |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
for my $method (qw(then get done fail else catch on_done on_cancel on_fail on_ready is_ready is_done is_failed failure)) { |
67
|
2
|
|
|
2
|
|
71
|
no strict 'refs'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
280
|
|
68
|
5067
|
|
|
5067
|
|
8327
|
*$method = sub { my $self = shift; $self->future->$method(@_) } |
|
5067
|
|
|
|
|
8383
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub new { |
72
|
2532
|
|
|
2532
|
0
|
57622
|
my ($class, %args) = @_; |
73
|
2532
|
|
|
|
|
6577
|
bless \%args, $class |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |