line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::CLI::Interact::Transport::Wrapper::Base; |
2
|
|
|
|
|
|
|
{ $Net::CLI::Interact::Transport::Wrapper::Base::VERSION = '2.400000' } |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
611
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
335
|
use Sub::Quote; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
78
|
|
6
|
1
|
|
|
1
|
|
8
|
use MooX::Types::MooseLike::Base qw(Int RegexpRef Str Object); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
7
|
1
|
|
|
1
|
|
7
|
use Time::HiRes qw( sleep ); |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
10
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Net::CLI::Interact::Role::FindMatch'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
{ |
12
|
|
|
|
|
|
|
package # hide from pause |
13
|
|
|
|
|
|
|
Net::CLI::Interact::Transport::Wrapper::Base::Options; |
14
|
1
|
|
|
1
|
|
145
|
use Moo; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
4
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'use_net_telnet_connection' => ( |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
isa => Int, |
20
|
|
|
|
|
|
|
default => quote_sub('0'), |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'irs_re' => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
isa => RegexpRef, |
26
|
|
|
|
|
|
|
default => quote_sub(q{ qr/(?:\015\012|\015|\012)/ }), # first wins |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'ors' => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
isa => Str, |
32
|
|
|
|
|
|
|
default => quote_sub(q{"\n"}), |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'timeout' => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
isa => quote_sub(q{ die "$_[0] is not a posint!" unless $_[0] > 0 }), |
38
|
|
|
|
|
|
|
default => quote_sub('10'), |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has 'app' => ( |
42
|
|
|
|
|
|
|
is => 'lazy', |
43
|
|
|
|
|
|
|
isa => Str, |
44
|
|
|
|
|
|
|
predicate => 1, |
45
|
|
|
|
|
|
|
clearer => 1, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has 'stash' => ( |
49
|
|
|
|
|
|
|
is => 'rw', |
50
|
|
|
|
|
|
|
isa => Str, |
51
|
|
|
|
|
|
|
default => quote_sub(q{''}), |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has 'wrapper' => ( |
55
|
|
|
|
|
|
|
is => 'lazy', |
56
|
|
|
|
|
|
|
isa => Object, |
57
|
|
|
|
|
|
|
predicate => 'connect_ready', |
58
|
|
|
|
|
|
|
clearer => 1, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _build_wrapper { |
62
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
63
|
|
|
|
|
|
|
$self->logger->log('transport', 'notice', 'connecting with: ', |
64
|
0
|
0
|
|
|
|
0
|
$self->app, (join ' ', map {($_ =~ m/\s/) ? ("'". $_ ."'") : $_} |
|
0
|
|
|
|
|
0
|
|
65
|
|
|
|
|
|
|
$self->runtime_options)); |
66
|
|
|
|
|
|
|
# this better be wrapped otherwise it'll blow up |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
0
|
0
|
sub init { (shift)->wrapper(@_) } |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub flush { |
72
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
73
|
2
|
|
|
|
|
38
|
my $content = $self->stash . $self->buffer; |
74
|
2
|
|
|
|
|
45
|
$self->stash(''); |
75
|
2
|
|
|
|
|
116
|
$self->buffer(''); |
76
|
2
|
|
|
|
|
40
|
return $content; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub disconnect { |
80
|
2
|
|
|
2
|
0
|
17
|
my $self = shift; |
81
|
2
|
|
|
|
|
36
|
$self->clear_wrapper; |
82
|
2
|
|
|
|
|
19
|
$self->flush; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
0
|
|
0
|
sub _abc { die "not implemented." } |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
0
|
0
|
sub put { _abc() } |
88
|
0
|
|
|
0
|
0
|
0
|
sub pump { _abc() } |
89
|
0
|
|
|
0
|
0
|
0
|
sub buffer { _abc() } |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
2
|
0
|
2476
|
sub DEMOLISH { (shift)->disconnect } |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub do_action { |
94
|
0
|
|
|
0
|
0
|
|
my ($self, $action) = @_; |
95
|
0
|
|
|
|
|
|
$self->logger->log('transport', 'info', 'callback received for', $action->type); |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if ($action->type eq 'match') { |
98
|
0
|
|
|
|
|
|
my $irs_re = $self->irs_re; |
99
|
0
|
|
|
|
|
|
my $cont = $action->continuation; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
while ($self->pump) { |
102
|
|
|
|
|
|
|
# remove control characters |
103
|
0
|
|
|
|
|
|
(my $buffer = $self->buffer) =~ s/[\000-\010\013\014\016-\032\034-\037]//g; |
104
|
0
|
|
|
|
|
|
$self->logger->log('dump', 'debug', "SEEN:\n'". $buffer. "'"); |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
if ($buffer =~ m/^(.*$irs_re)(.*)/s) { |
107
|
0
|
|
|
|
|
|
$self->stash($self->stash . $1); |
108
|
0
|
|
0
|
|
|
|
$self->buffer($2 || ''); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
0
|
|
|
|
if ($cont and $self->find_match($self->buffer, $cont->first->value)) { |
|
|
0
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->logger->log('transport', 'debug', 'continuation matched'); |
113
|
0
|
|
|
|
|
|
$self->buffer(''); |
114
|
0
|
|
|
|
|
|
$self->put($cont->last->value); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif (my $hit = $self->find_match($self->buffer, $action->value)) { |
117
|
0
|
|
|
|
|
|
$self->logger->log('transport', 'info', |
118
|
|
|
|
|
|
|
sprintf 'output matched %s, storing and returning', $hit); |
119
|
0
|
|
|
|
|
|
$action->prompt_hit($hit); |
120
|
0
|
|
|
|
|
|
$action->response_stash($self->stash); |
121
|
0
|
|
|
|
|
|
$action->response($self->buffer); |
122
|
0
|
|
|
|
|
|
$self->flush; |
123
|
0
|
|
|
|
|
|
last; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
|
|
|
|
|
|
$self->logger->log('transport', 'debug', "nope, doesn't (yet) match", |
127
|
0
|
0
|
|
|
|
|
(ref $action->value eq ref [] ? (join '|', @{$action->value}) |
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
: $action->value)); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
sleep(0.01); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
0
|
0
|
|
|
|
|
if ($action->type eq 'send') { |
135
|
0
|
|
|
|
|
|
my $command = sprintf $action->value, @{ $action->params }; |
|
0
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
$self->logger->log('dialogue', 'notice', 'queueing data for send: "'. $command .'"'); |
137
|
0
|
0
|
|
|
|
|
$self->put( $command, ($action->no_ors ? () : $self->ors) ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |