line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Objects; |
2
|
18
|
|
|
18
|
|
936
|
use version; |
|
18
|
|
|
|
|
1308
|
|
|
18
|
|
|
|
|
69
|
|
3
|
|
|
|
|
|
|
$Gearman::Objects::VERSION = qv("2.001_001"); |
4
|
|
|
|
|
|
|
|
5
|
18
|
|
|
18
|
|
1071
|
use strict; |
|
18
|
|
|
|
|
22
|
|
|
18
|
|
|
|
|
256
|
|
6
|
18
|
|
|
18
|
|
46
|
use warnings; |
|
18
|
|
|
|
|
18
|
|
|
18
|
|
|
|
|
382
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Gearman::Objects - a parrent class for L and L |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 METHODS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
18
|
|
|
18
|
|
46
|
use constant DEFAULT_PORT => 4730; |
|
18
|
|
|
|
|
28
|
|
|
18
|
|
|
|
|
871
|
|
17
|
|
|
|
|
|
|
|
18
|
18
|
|
|
18
|
|
61
|
use Carp (); |
|
18
|
|
|
|
|
16
|
|
|
18
|
|
|
|
|
202
|
|
19
|
18
|
|
|
18
|
|
3264
|
use IO::Socket::IP (); |
|
18
|
|
|
|
|
140101
|
|
|
18
|
|
|
|
|
277
|
|
20
|
18
|
|
|
18
|
|
11481
|
use IO::Socket::SSL (); |
|
18
|
|
|
|
|
573643
|
|
|
18
|
|
|
|
|
560
|
|
21
|
18
|
|
|
18
|
|
111
|
use Socket (); |
|
18
|
|
|
|
|
20
|
|
|
18
|
|
|
|
|
369
|
|
22
|
|
|
|
|
|
|
|
23
|
18
|
|
|
|
|
117
|
use fields qw/ |
24
|
|
|
|
|
|
|
debug |
25
|
|
|
|
|
|
|
job_servers |
26
|
|
|
|
|
|
|
js_count |
27
|
|
|
|
|
|
|
prefix |
28
|
|
|
|
|
|
|
use_ssl |
29
|
|
|
|
|
|
|
ssl_socket_cb |
30
|
18
|
|
|
18
|
|
2506
|
/; |
|
18
|
|
|
|
|
6135
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
33
|
25
|
|
|
25
|
0
|
5921
|
my Gearman::Objects $self = shift; |
34
|
25
|
|
|
|
|
40
|
my (%opts) = @_; |
35
|
25
|
100
|
|
|
|
60
|
unless (ref($self)) { |
36
|
11
|
|
|
|
|
19
|
$self = fields::new($self); |
37
|
|
|
|
|
|
|
} |
38
|
25
|
|
|
|
|
2992
|
$self->{job_servers} = []; |
39
|
25
|
|
|
|
|
31
|
$self->{js_count} = 0; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$opts{job_servers} |
42
|
|
|
|
|
|
|
&& $self->set_job_servers( |
43
|
|
|
|
|
|
|
ref($opts{job_servers}) |
44
|
4
|
|
|
|
|
12
|
? @{ $opts{job_servers} } |
45
|
25
|
100
|
|
|
|
72
|
: [$opts{job_servers}] |
|
|
100
|
|
|
|
|
|
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
25
|
|
|
|
|
76
|
$self->debug($opts{debug}); |
49
|
25
|
|
|
|
|
73
|
$self->prefix($opts{prefix}); |
50
|
25
|
100
|
|
|
|
66
|
if ($self->use_ssl($opts{use_ssl})) { |
51
|
2
|
|
|
|
|
2
|
$self->{ssl_socket_cb} = $opts{ssl_socket_cb}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
25
|
|
|
|
|
48
|
return $self; |
55
|
|
|
|
|
|
|
} ## end sub new |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 job_servers([$js]) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
getter/setter |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
C<$js> array reference or scalar |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub job_servers { |
66
|
6
|
|
|
6
|
1
|
930
|
my ($self) = shift; |
67
|
6
|
100
|
|
|
|
15
|
(@_) && $self->set_job_servers(@_); |
68
|
|
|
|
|
|
|
|
69
|
6
|
100
|
|
|
|
20
|
return wantarray ? @{ $self->{job_servers} } : $self->{job_servers}; |
|
1
|
|
|
|
|
7
|
|
70
|
|
|
|
|
|
|
} ## end sub job_servers |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 set_job_servers($js) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
set job_servers attribute by canonicalized C<$js>_ |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub set_job_servers { |
79
|
10
|
|
|
10
|
1
|
11
|
my $self = shift; |
80
|
10
|
|
|
|
|
23
|
my $list = $self->canonicalize_job_servers(@_); |
81
|
|
|
|
|
|
|
|
82
|
10
|
|
|
|
|
14
|
$self->{js_count} = scalar @$list; |
83
|
10
|
|
|
|
|
12
|
return $self->{job_servers} = $list; |
84
|
|
|
|
|
|
|
} ## end sub set_job_servers |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 canonicalize_job_servers($js) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
C<$js> array reference or scalar |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
B [canonicalized list] |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub canonicalize_job_servers { |
95
|
15
|
|
|
15
|
1
|
272
|
my ($self) = shift; |
96
|
15
|
|
|
|
|
8
|
my @in; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# take arrayref or array |
99
|
15
|
100
|
|
|
|
26
|
if (ref($_[0])) { |
100
|
5
|
50
|
|
|
|
10
|
ref($_[0]) eq "ARRAY" |
101
|
|
|
|
|
|
|
|| Carp::croak |
102
|
|
|
|
|
|
|
"canonicalize_job_servers argument is not a reference on array"; |
103
|
5
|
|
|
|
|
5
|
@in = @{ $_[0] }; |
|
5
|
|
|
|
|
11
|
|
104
|
|
|
|
|
|
|
} ## end if (ref($_[0])) |
105
|
|
|
|
|
|
|
else { |
106
|
10
|
|
|
|
|
15
|
@in = @_; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
15
|
|
|
|
|
16
|
my $out = []; |
110
|
15
|
|
|
|
|
17
|
foreach my $i (@in) { |
111
|
13
|
50
|
|
|
|
16
|
$i |
112
|
|
|
|
|
|
|
|| Carp::croak |
113
|
|
|
|
|
|
|
"canonicalize_job_servers argument contails an undefined parameter"; |
114
|
13
|
50
|
|
|
|
31
|
if ($i !~ /:/) { |
115
|
0
|
|
|
|
|
0
|
$i .= ':' . Gearman::Objects::DEFAULT_PORT; |
116
|
|
|
|
|
|
|
} |
117
|
13
|
|
|
|
|
7
|
push @{$out}, $i; |
|
13
|
|
|
|
|
23
|
|
118
|
|
|
|
|
|
|
} ## end foreach my $i (@in) |
119
|
15
|
|
|
|
|
32
|
return $out; |
120
|
|
|
|
|
|
|
} ## end sub canonicalize_job_servers |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub debug { |
123
|
33
|
|
|
33
|
0
|
493
|
return shift->_property("debug", @_); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 prefix([$prefix]) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
getter/setter |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub prefix { |
133
|
33
|
|
|
33
|
1
|
460
|
return shift->_property("prefix", @_); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub use_ssl { |
137
|
33
|
|
|
33
|
0
|
461
|
return shift->_property("use_ssl", @_); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 socket($host_port, [$timeout]) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
depends on C |
143
|
|
|
|
|
|
|
prepare L |
144
|
|
|
|
|
|
|
or L |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
C<$host_port> peer address |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
C<$timeout> default: 1 |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
B depends on C IO::Socket::(IP|SSL) on success |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub socket { |
163
|
3
|
|
|
3
|
1
|
439
|
my ($self, $pa, $t) = @_; |
164
|
3
|
|
|
|
|
18
|
my ($h, $p) = ($pa =~ /^(.*):(\d+)$/); |
165
|
|
|
|
|
|
|
|
166
|
3
|
|
100
|
|
|
23
|
my %opts = ( |
167
|
|
|
|
|
|
|
PeerPort => $p, |
168
|
|
|
|
|
|
|
PeerHost => $h, |
169
|
|
|
|
|
|
|
Timeout => $t || 1 |
170
|
|
|
|
|
|
|
); |
171
|
3
|
|
|
|
|
5
|
my $sc; |
172
|
3
|
100
|
|
|
|
10
|
if ($self->use_ssl()) { |
173
|
1
|
|
|
|
|
1
|
$sc = "IO::Socket::SSL"; |
174
|
1
|
50
|
|
|
|
4
|
$self->{ssl_socket_cb} && $self->{ssl_socket_cb}->(\%opts); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
else { |
177
|
2
|
|
|
|
|
2
|
$sc = "IO::Socket::IP"; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
3
|
|
|
|
|
27
|
my $s = $sc->new(%opts); |
181
|
3
|
50
|
|
|
|
66510
|
$s || Carp::carp("connection failed error='$@'", |
|
|
100
|
|
|
|
|
|
182
|
|
|
|
|
|
|
$self->use_ssl() |
183
|
|
|
|
|
|
|
? ", ssl_error='$IO::Socket::SSL::SSL_ERROR'" |
184
|
|
|
|
|
|
|
: ""); |
185
|
|
|
|
|
|
|
|
186
|
3
|
|
|
|
|
250
|
return $s; |
187
|
|
|
|
|
|
|
} ## end sub socket |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 sock_nodelay($sock) |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
set TCP_NODELAY on $sock, die on failure |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
sub sock_nodelay { |
195
|
0
|
|
|
0
|
1
|
0
|
my ($self, $sock) = @_; |
196
|
0
|
0
|
|
|
|
0
|
setsockopt($sock, Socket::IPPROTO_TCP, Socket::TCP_NODELAY, pack("l", 1)) |
197
|
|
|
|
|
|
|
or Carp::croak "setsockopt: $!"; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# |
201
|
|
|
|
|
|
|
# _property($name, [$value]) |
202
|
|
|
|
|
|
|
# set/get |
203
|
|
|
|
|
|
|
sub _property { |
204
|
99
|
|
|
99
|
|
75
|
my $self = shift; |
205
|
99
|
|
|
|
|
72
|
my $name = shift; |
206
|
99
|
50
|
|
|
|
126
|
$name || return; |
207
|
99
|
100
|
|
|
|
144
|
if (@_) { |
208
|
81
|
|
|
|
|
116
|
$self->{$name} = shift; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
99
|
|
|
|
|
190
|
return $self->{$name}; |
212
|
|
|
|
|
|
|
} ## end sub _property |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
1; |