line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Queue::Gearman::Message; |
2
|
4
|
|
|
4
|
|
68174
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
123
|
|
3
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
110
|
|
4
|
4
|
|
|
4
|
|
2518
|
use utf8; |
|
4
|
|
|
|
|
41
|
|
|
4
|
|
|
|
|
17
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
129
|
use Carp qw/croak/; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
327
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
2038
|
use parent qw/Exporter/; |
|
4
|
|
|
|
|
1105
|
|
|
4
|
|
|
|
|
22
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our (%EXPORT_TAGS, @EXPORT_OK); |
13
|
|
|
|
|
|
|
BEGIN { |
14
|
4
|
|
|
4
|
|
692
|
$EXPORT_TAGS{functions} = [qw/build_header build_message parse_header parse_args/]; |
15
|
4
|
|
|
|
|
8
|
$EXPORT_TAGS{constants} = [qw/ARGS_DELIMITER HEADER_BYTES/]; |
16
|
4
|
|
|
|
|
6
|
$EXPORT_TAGS{headers} = []; |
17
|
4
|
|
|
|
|
6
|
$EXPORT_TAGS{msgtypes} = []; |
18
|
4
|
|
|
|
|
9
|
$EXPORT_TAGS{all} = \@EXPORT_OK; |
19
|
4
|
|
|
|
|
17
|
push @EXPORT_OK => map { @{$EXPORT_TAGS{$_}} } keys %EXPORT_TAGS; |
|
20
|
|
|
|
|
13
|
|
|
20
|
|
|
|
|
165
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use constant +{ |
23
|
4
|
|
|
|
|
1059
|
ARGS_DELIMITER => "\0", |
24
|
|
|
|
|
|
|
HEADER_BYTES => 12, |
25
|
4
|
|
|
4
|
|
21
|
}; |
|
4
|
|
|
|
|
6
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my (%MAGIC_CODE, %MAGIC_CODE_REV, %MSGTYPE, %MSGTYPE_REV); |
28
|
|
|
|
|
|
|
BEGIN { |
29
|
4
|
|
|
4
|
|
18
|
%MAGIC_CODE = ( |
30
|
|
|
|
|
|
|
REQ => "\0REQ", |
31
|
|
|
|
|
|
|
RES => "\0RES", |
32
|
|
|
|
|
|
|
); |
33
|
4
|
|
|
|
|
47
|
%MAGIC_CODE_REV = reverse %MAGIC_CODE; |
34
|
4
|
|
|
|
|
129
|
%MSGTYPE = ( |
35
|
|
|
|
|
|
|
REQ => +{ |
36
|
|
|
|
|
|
|
CAN_DO => 1, |
37
|
|
|
|
|
|
|
CANT_DO => 2, |
38
|
|
|
|
|
|
|
RESET_ABILITIES => 3, |
39
|
|
|
|
|
|
|
PRE_SLEEP => 4, |
40
|
|
|
|
|
|
|
SUBMIT_JOB => 7, |
41
|
|
|
|
|
|
|
GRAB_JOB => 9, |
42
|
|
|
|
|
|
|
WORK_STATUS => 12, |
43
|
|
|
|
|
|
|
WORK_COMPLETE => 13, |
44
|
|
|
|
|
|
|
WORK_FAIL => 14, |
45
|
|
|
|
|
|
|
GET_STATUS => 15, |
46
|
|
|
|
|
|
|
ECHO_REQ => 16, |
47
|
|
|
|
|
|
|
SUBMIT_JOB_BG => 18, |
48
|
|
|
|
|
|
|
SUBMIT_JOB_HIGH => 21, |
49
|
|
|
|
|
|
|
SET_CLIENT_ID => 22, |
50
|
|
|
|
|
|
|
CAN_DO_TIMEOUT => 23, |
51
|
|
|
|
|
|
|
ALL_YOURS => 24, |
52
|
|
|
|
|
|
|
WORK_EXCEPTION => 25, |
53
|
|
|
|
|
|
|
OPTION_REQ => 26, |
54
|
|
|
|
|
|
|
WORK_DATA => 28, |
55
|
|
|
|
|
|
|
WORK_WARNING => 29, |
56
|
|
|
|
|
|
|
GRAB_JOB_UNIQ => 30, |
57
|
|
|
|
|
|
|
SUBMIT_JOB_HIGH_BG => 32, |
58
|
|
|
|
|
|
|
SUBMIT_JOB_LOW => 33, |
59
|
|
|
|
|
|
|
SUBMIT_JOB_LOW_BG => 34, |
60
|
|
|
|
|
|
|
SUBMIT_JOB_SCHED => 35, |
61
|
|
|
|
|
|
|
SUBMIT_JOB_EPOCH => 36, |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
RES => +{ |
64
|
|
|
|
|
|
|
NOOP => 6, |
65
|
|
|
|
|
|
|
JOB_CREATED => 8, |
66
|
|
|
|
|
|
|
NO_JOB => 10, |
67
|
|
|
|
|
|
|
JOB_ASSIGN => 11, |
68
|
|
|
|
|
|
|
WORK_STATUS => 12, |
69
|
|
|
|
|
|
|
WORK_COMPLETE => 13, |
70
|
|
|
|
|
|
|
WORK_FAIL => 14, |
71
|
|
|
|
|
|
|
ECHO_RES => 17, |
72
|
|
|
|
|
|
|
ERROR => 19, |
73
|
|
|
|
|
|
|
STATUS_RES => 20, |
74
|
|
|
|
|
|
|
WORK_EXCEPTION => 25, |
75
|
|
|
|
|
|
|
OPTION_RES => 27, |
76
|
|
|
|
|
|
|
WORK_DATA => 28, |
77
|
|
|
|
|
|
|
WORK_WARNING => 29, |
78
|
|
|
|
|
|
|
JOB_ASSIGN_UNIQ => 31, |
79
|
|
|
|
|
|
|
}, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
%MSGTYPE_REV = map { |
82
|
4
|
|
|
|
|
10
|
$_ => +{ |
83
|
8
|
|
|
|
|
9
|
reverse %{$MSGTYPE{$_}}, |
|
8
|
|
|
|
|
2171
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} keys %MSGTYPE; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my %BUILD_HEADER_CACHE; |
89
|
|
|
|
|
|
|
sub build_header { |
90
|
166
|
|
|
166
|
0
|
153
|
my ($context, $msgtype) = @_; |
91
|
166
|
|
66
|
|
|
366
|
return $BUILD_HEADER_CACHE{$context}{$msgtype} ||= do { |
92
|
164
|
|
|
|
|
146
|
local $Carp::CarpLevel = $Carp::CarpLevel + 1; |
93
|
164
|
|
|
|
|
171
|
_build_header($context, $msgtype); |
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _build_header { |
98
|
164
|
|
|
164
|
|
125
|
my ($context, $msgtype) = @_; |
99
|
164
|
50
|
|
|
|
233
|
my $magic_code = $MAGIC_CODE{$context} or croak "invalid context: $context"; |
100
|
164
|
50
|
|
|
|
251
|
my $msgtype_code = $MSGTYPE{$context}{$msgtype} or croak "invalid msgtype: $msgtype"; |
101
|
164
|
|
|
|
|
569
|
return $magic_code . pack 'N', $msgtype_code; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub build_message { |
105
|
3
|
|
|
3
|
0
|
9
|
my $header = shift; |
106
|
3
|
|
|
|
|
8
|
my $args = join ARGS_DELIMITER, @_; |
107
|
3
|
|
|
|
|
10
|
my $bytes = pack 'N', length $args; |
108
|
3
|
|
|
|
|
16
|
return $header.$bytes.$args; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub parse_header { |
112
|
2
|
|
|
2
|
0
|
7
|
my $header = shift; |
113
|
2
|
|
|
|
|
11
|
my ($magic_code, $msgtype_code, $bytes) = unpack 'a4NN', $header; |
114
|
2
|
|
|
|
|
5
|
my $context = $MAGIC_CODE_REV{$magic_code}; |
115
|
2
|
|
|
|
|
5
|
my $msgtype = $MSGTYPE_REV{$context}{$msgtype_code}; |
116
|
2
|
|
|
|
|
11
|
return ($context, $msgtype, $bytes); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub parse_args { |
120
|
3
|
|
|
3
|
0
|
11
|
my $args = shift; |
121
|
3
|
|
|
|
|
18
|
return split ARGS_DELIMITER, $args; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Creates HEADER_*/MSGTYPE_* constants, and creates `build_header` cache. |
125
|
|
|
|
|
|
|
BEGIN { |
126
|
4
|
|
|
4
|
|
24
|
require constant; |
127
|
4
|
|
|
|
|
13
|
for my $context (keys %MSGTYPE) { |
128
|
8
|
|
|
|
|
7
|
for my $msgtype (keys %{ $MSGTYPE{$context} }) { |
|
8
|
|
|
|
|
44
|
|
129
|
164
|
|
|
|
|
219
|
my $name = "HEADER_${context}_${msgtype}"; |
130
|
164
|
|
|
|
|
185
|
my $value = build_header($context, $msgtype); |
131
|
164
|
|
|
|
|
3045
|
constant->import($name => $value); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# export |
134
|
164
|
|
|
|
|
203
|
push @EXPORT_OK => $name; |
135
|
164
|
|
|
|
|
117
|
push @{ $EXPORT_TAGS{headers} } => $name; |
|
164
|
|
|
|
|
270
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
4
|
|
|
|
|
8
|
for my $context (keys %MSGTYPE) { |
140
|
8
|
|
|
|
|
8
|
for my $msgtype (keys %{ $MSGTYPE{$context} }) { |
|
8
|
|
|
|
|
34
|
|
141
|
164
|
|
|
|
|
216
|
my $name = "MSGTYPE_${context}_${msgtype}"; |
142
|
164
|
|
|
|
|
2608
|
constant->import($name => $msgtype); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# export |
145
|
164
|
|
|
|
|
190
|
push @EXPORT_OK => $name; |
146
|
164
|
|
|
|
|
109
|
push @{ $EXPORT_TAGS{msgtypes} } => $name; |
|
164
|
|
|
|
|
447
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
__END__ |