| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MozRepl::Client; |
|
2
|
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
61
|
use strict; |
|
|
12
|
|
|
|
|
23
|
|
|
|
12
|
|
|
|
|
569
|
|
|
4
|
12
|
|
|
12
|
|
66
|
use warnings; |
|
|
12
|
|
|
|
|
20
|
|
|
|
12
|
|
|
|
|
743
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
12
|
|
|
12
|
|
63
|
use base qw(Class::Accessor::Fast); |
|
|
12
|
|
|
|
|
22
|
|
|
|
12
|
|
|
|
|
1382
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/telnet connect_args extra_telnet_args/); |
|
9
|
|
|
|
|
|
|
|
|
10
|
12
|
|
|
12
|
|
12478
|
use Carp::Clan qw(croak); |
|
|
12
|
|
|
|
|
29219
|
|
|
|
12
|
|
|
|
|
84
|
|
|
11
|
12
|
|
|
12
|
|
14433
|
use Data::Dump qw(dump); |
|
|
12
|
|
|
|
|
93217
|
|
|
|
12
|
|
|
|
|
1111
|
|
|
12
|
12
|
|
|
12
|
|
21912
|
use Net::Telnet; |
|
|
12
|
|
|
|
|
786132
|
|
|
|
12
|
|
|
|
|
615
|
|
|
13
|
12
|
|
|
12
|
|
111
|
use Text::SimpleTable; |
|
|
12
|
|
|
|
|
30
|
|
|
|
12
|
|
|
|
|
152
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
MozRepl::Client - MozRepl client class using telnet. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
version 0.03 |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 new($ctx, $args) |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Create instance. two arguments. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over 4 |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item $ctx |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Context object. see L. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item $args |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Hash reference. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item host |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Default value is "localhost". |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item port |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Default value is 4242. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item timeout |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Default value is 10(sec). |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item extra_client_args |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
See L's new method arguments. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=back |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=back |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub new { |
|
68
|
11
|
|
|
11
|
1
|
122
|
my ($class, $ctx, $args) = @_; |
|
69
|
|
|
|
|
|
|
|
|
70
|
11
|
|
50
|
|
|
168
|
$args->{host} ||= $ENV{MOZREPL_HOST} || 'localhost'; |
|
|
|
|
33
|
|
|
|
|
|
71
|
11
|
|
50
|
|
|
142
|
$args->{port} ||= $ENV{MOZREPL_PORT} || 4242; |
|
|
|
|
33
|
|
|
|
|
|
72
|
11
|
|
50
|
|
|
447
|
$args->{timeout} ||= $ENV{MOZREPL_TIMEOUT} || 10; |
|
|
|
|
33
|
|
|
|
|
|
73
|
11
|
|
50
|
|
|
76
|
$args->{extra_client_args} ||= {}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
11
|
50
|
|
|
|
65
|
$args->{extra_client_args}->{binmode} = 1 if ($^O eq "cygwin"); |
|
76
|
|
|
|
|
|
|
|
|
77
|
11
|
50
|
|
|
|
62
|
if ($ctx->log->is_debug) { |
|
78
|
11
|
|
|
|
|
99
|
my $table = Text::SimpleTable->new([20, 'client_arg_name'], [40, 'client_arg_value']); |
|
79
|
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
907
|
$table->row('host', $args->{host}); |
|
81
|
11
|
|
|
|
|
1014
|
$table->row('port', $args->{port}); |
|
82
|
11
|
|
|
|
|
758
|
$table->row('timeout', $args->{timeout}); |
|
83
|
11
|
|
|
|
|
821
|
$table->row('extra_client_args', dump($args->{extra_client_args})); |
|
84
|
|
|
|
|
|
|
|
|
85
|
11
|
|
|
|
|
2338
|
$ctx->log->debug("---- Client arguments ----\n" . $table->draw); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
11
|
|
|
|
|
94
|
my $self = $class->SUPER::new({ |
|
89
|
11
|
|
|
|
|
46
|
telnet => Net::Telnet->new(%{$args->{extra_client_args}}), |
|
90
|
|
|
|
|
|
|
connect_args => { |
|
91
|
|
|
|
|
|
|
Host => $args->{host}, |
|
92
|
|
|
|
|
|
|
Port => int($args->{port}), |
|
93
|
|
|
|
|
|
|
Timeout => int($args->{timeout}) |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
}); |
|
96
|
|
|
|
|
|
|
|
|
97
|
11
|
|
|
|
|
3099
|
return $self; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 setup($ctx, $args) |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Two arguments. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item $ctx |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Context object. see L. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item $args |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Hash reference. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=over 4 |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item host |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Default value is "localhost". |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item port |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Default value is 4242. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item timeout |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Default value is 10(sec). |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub setup { |
|
135
|
11
|
|
|
11
|
1
|
74
|
my ($self, $ctx, $args) = @_; |
|
136
|
|
|
|
|
|
|
|
|
137
|
11
|
|
|
|
|
45
|
my $telnet = $self->telnet; |
|
138
|
11
|
|
|
|
|
239
|
my %connect_args = %{$self->connect_args}; |
|
|
11
|
|
|
|
|
46
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
11
|
50
|
|
|
|
253
|
$connect_args{Host} = $args->{host} if ($args->{host}); |
|
141
|
11
|
50
|
|
|
|
46
|
$connect_args{Port} = int($args->{port}) if (defined $args->{port}); |
|
142
|
11
|
50
|
33
|
|
|
56
|
$connect_args{Timeoout} = int($args->{timeout}) if (defined $args->{timeout} && $args->{timeout} > 0); |
|
143
|
|
|
|
|
|
|
|
|
144
|
11
|
0
|
|
|
|
84
|
unless ($telnet->open(%connect_args)) { |
|
145
|
0
|
|
|
|
|
|
my $message = q|Can't connect to | . sprintf("%s:%d", $connect_args{Host}, $connect_args{Port}); |
|
146
|
|
|
|
|
|
|
# $ctx->log->fatal($message); |
|
147
|
0
|
|
|
|
|
|
croak($message); |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# initialize repl object name and prompt pattern |
|
151
|
0
|
|
|
|
|
|
my @msg = $telnet->waitfor('/repl\d*> /'); |
|
152
|
0
|
|
|
|
|
|
my $prompt = pop @msg; |
|
153
|
0
|
|
|
|
|
|
$prompt = '/' . $prompt . '/'; |
|
154
|
0
|
|
|
|
|
|
my ($repl) = ($prompt =~ m|(repl\d*)|); |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$ctx->log->debug('repl name: ' . $repl); |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
$telnet->prompt($prompt); |
|
159
|
0
|
|
|
|
|
|
$ctx->repl($repl); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 execute($ctx, $command) |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Execute command and return result string or lines as array. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over 4 |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item $ctx |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Context object. see L. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item $command |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Command string. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub execute { |
|
181
|
0
|
|
|
0
|
1
|
|
my ($self, $ctx, $command) = @_; |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
### adhoc |
|
184
|
0
|
0
|
|
|
|
|
$command = join(" ", split(/\n/, $command)) if ($^O eq "cygwin"); |
|
185
|
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
my $message = [map { chomp; $_ } $self->telnet->cmd(String => $command)]; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
|
188
|
0
|
0
|
|
|
|
|
if ($ctx->log->is_debug) { |
|
189
|
0
|
|
|
|
|
|
my $table = Text::SimpleTable->new([10, 'type'], [40, 'content']); |
|
190
|
0
|
|
|
|
|
|
$table->row('command', $command); |
|
191
|
0
|
|
|
|
|
|
$table->row('result', join("\n", @$message)); |
|
192
|
0
|
|
|
|
|
|
$ctx->log->debug($table->draw); |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
0
|
0
|
|
|
|
|
return wantarray ? @$message : join("\n", @$message); |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 prompt($prompt) |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Telnet prompt string. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub prompt { |
|
205
|
0
|
|
|
0
|
1
|
|
my ($self, $prompt) = @_; |
|
206
|
|
|
|
|
|
|
|
|
207
|
0
|
0
|
|
|
|
|
if ($prompt) { |
|
208
|
0
|
|
|
|
|
|
$self->telnet->prompt($prompt); |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
else { |
|
211
|
0
|
|
|
|
|
|
$self->telnet->prompt; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 quit() |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Quit connection. |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub quit { |
|
222
|
0
|
|
|
0
|
1
|
|
my ($self, $ctx, $args) = @_; |
|
223
|
|
|
|
|
|
|
### logging |
|
224
|
0
|
|
|
|
|
|
$self->telnet->quit; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=over 4 |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item L |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 AUTHOR |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Toru Yamaguchi, C<< >> |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 BUGS |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
242
|
|
|
|
|
|
|
C, or through the web interface at |
|
243
|
|
|
|
|
|
|
L. I will be notified, and then you'll automatically be |
|
244
|
|
|
|
|
|
|
notified of progress on your bug as I make changes. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Copyright 2007 Toru Yamaguchi, All Rights Reserved. |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
251
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
1; # End of MozRepl::Client |