line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Telnet::Gearman; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20443
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
5
|
use base qw/Net::Telnet/; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1423
|
|
6
|
1
|
|
|
1
|
|
59156
|
use Net::Telnet::Gearman::Worker; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
732
|
use Net::Telnet::Gearman::Function; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
20
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.05000'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Net::Telnet::Gearman - interact with a Gearman server through its telnet interface |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Net::Telnet::Gearman; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $session = Net::Telnet::Gearman->new( |
20
|
|
|
|
|
|
|
Host => '127.0.0.1', |
21
|
|
|
|
|
|
|
Port => 4730, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my @workers = $session->workers(); |
25
|
|
|
|
|
|
|
my @functions = $session->status(); |
26
|
|
|
|
|
|
|
my $version = $session->version(); |
27
|
|
|
|
|
|
|
my $result = $session->maxqueue( reverse => 15 ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$session->shutdown('graceful'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This is currently only tested with Gearman v0.10. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This is the same as in L except for that there is |
40
|
|
|
|
|
|
|
called C<< $self->open() >> for you. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# There's a new cmd_prompt in town. |
48
|
0
|
0
|
|
|
|
|
my $self = $class->SUPER::new(@_) or return; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->open(); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 workers |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This sends back a list of all workers, their file descriptors, |
58
|
|
|
|
|
|
|
their IPs, their IDs, and a list of registered functions they can |
59
|
|
|
|
|
|
|
perform. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
See also: L |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This method accepts any parameters the L C |
64
|
|
|
|
|
|
|
method does accept. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub workers { |
69
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->print('workers'); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my @workers = (); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
while ( my $line = $self->getline(@args) ) { |
76
|
0
|
0
|
|
|
|
|
last if $line eq ".\n"; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
push @workers, Net::Telnet::Gearman::Worker->parse_line($line); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
return wantarray ? @workers : \@workers; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 status |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This sends back a list of all registered functions. Next to |
87
|
|
|
|
|
|
|
each function is the number of jobs in the queue, the number of |
88
|
|
|
|
|
|
|
running jobs, and the number of capable workers. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
See also: L |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This method accepts any parameters the L C |
93
|
|
|
|
|
|
|
method does accept. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub status { |
98
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$self->print('status'); |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my @functions = (); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
while ( my $line = $self->getline(@args) ) { |
105
|
0
|
0
|
|
|
|
|
last if $line eq ".\n"; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
next unless my $row = Net::Telnet::Gearman::Function->parse_line($line); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
push @functions, $row; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
return wantarray ? @functions : \@functions; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 maxqueue |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This sets the maximum queue size for a function. If no size is |
118
|
|
|
|
|
|
|
given, the default is used. If the size is negative, then the queue |
119
|
|
|
|
|
|
|
is set to be unlimited. This sends back a single line with "OK". |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Arguments: |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=over 4 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item * Function name |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * Maximum queue size (optional) |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub maxqueue { |
134
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
135
|
0
|
|
|
|
|
|
unshift @args, 'maxqueue'; |
136
|
0
|
|
|
|
|
|
return $self->_print_and_getline(@args); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 shutdown |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Shutdown the server. If the optional "graceful" argument is used, |
142
|
|
|
|
|
|
|
close the listening socket and let all existing connections |
143
|
|
|
|
|
|
|
complete. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Arguments: |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=over 4 |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * "graceful" (optional) |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub shutdown { |
156
|
0
|
|
|
0
|
1
|
|
my ( $self, $graceful ) = @_; |
157
|
0
|
|
|
|
|
|
my @args = ('shutdown'); |
158
|
0
|
0
|
|
|
|
|
push @args, 'graceful' if $graceful; |
159
|
0
|
|
|
|
|
|
return $self->_print_and_getline(@args); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 version |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Send back the version of the server. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub version { |
169
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
170
|
0
|
|
|
|
|
|
return $self->_print_and_getline('version'); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub _print_and_getline { |
174
|
0
|
|
|
0
|
|
|
my ( $self, @args ) = @_; |
175
|
0
|
|
|
|
|
|
$self->print( join ' ', @args ); |
176
|
0
|
|
|
|
|
|
my $line = $self->getline(); |
177
|
0
|
|
|
|
|
|
chomp $line; |
178
|
0
|
|
|
|
|
|
return $line; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Johannes Plunien Eplu@cpan.orgE |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Copyright 2009 by Johannes Plunien |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
190
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 SEE ALSO |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=over 4 |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item * L |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * L |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=back |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 REPOSITORY |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |