| 1 | package Net::CLI::Interact::Transport::Wrapper::Base; | ||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||
| 3 | 1 | $Net::CLI::Interact::Transport::Wrapper::Base::VERSION = '2.143070'; | |||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MooX::Types::MooseLike::Base qw(Int RegexpRef Str Object); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | with 'Net::CLI::Interact::Role::FindMatch'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | { | ||||||||||||||||||||||||||||||||
| 13 | package # hide from pause | ||||||||||||||||||||||||||||||||
| 14 | Net::CLI::Interact::Transport::Wrapper::Base::Options; | ||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 1 | has 'use_net_telnet_connection' => ( | |||||||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 20 | isa => Int, | ||||||||||||||||||||||||||||||||
| 21 | default => quote_sub('0'), | ||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1 | has 'irs_re' => ( | |||||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 26 | isa => RegexpRef, | ||||||||||||||||||||||||||||||||
| 27 | default => quote_sub(q{ qr/(?:\015\012|\015|\012)/ }), # first wins | ||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 1 | has 'ors' => ( | |||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 32 | isa => Str, | ||||||||||||||||||||||||||||||||
| 33 | default => quote_sub(q{"\n"}), | ||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 1 | has 'timeout' => ( | |||||||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 38 | isa => quote_sub(q{ die "$_[0] is not a posint!" unless $_[0] > 0 }), | ||||||||||||||||||||||||||||||||
| 39 | default => quote_sub('10'), | ||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 1 | has 'app' => ( | |||||||||||||||||||||||||||||||
| 43 | is => 'lazy', | ||||||||||||||||||||||||||||||||
| 44 | isa => Str, | ||||||||||||||||||||||||||||||||
| 45 | predicate => 1, | ||||||||||||||||||||||||||||||||
| 46 | clearer => 1, | ||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 1 | has 'stash' => ( | |||||||||||||||||||||||||||||||
| 50 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 51 | isa => Str, | ||||||||||||||||||||||||||||||||
| 52 | default => quote_sub(q{''}), | ||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 1 | has 'wrapper' => ( | |||||||||||||||||||||||||||||||
| 56 | is => 'lazy', | ||||||||||||||||||||||||||||||||
| 57 | isa => Object, | ||||||||||||||||||||||||||||||||
| 58 | predicate => 'connect_ready', | ||||||||||||||||||||||||||||||||
| 59 | clearer => 1, | ||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | sub _build_wrapper { | ||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_build_wrapper: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 64 | $self->logger->log('transport', 'notice', 'connecting with: ', | ||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $self->app, (join ' ', map {($_ =~ m/\s/) ? ("'". $_ ."'") : $_} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | $self->runtime_options)); | ||||||||||||||||||||||||||||||||
| 67 | # this better be wrapped otherwise it'll blow up | ||||||||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub init { (shift)->wrapper(@_) } | ||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | sub flush { | ||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
flush: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 74 | 2 | my $content = $self->stash . $self->buffer; | |||||||||||||||||||||||||||||||
| 75 | 2 | $self->stash(''); | |||||||||||||||||||||||||||||||
| 76 | 2 | $self->buffer(''); | |||||||||||||||||||||||||||||||
| 77 | 2 | return $content; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | sub disconnect { | ||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 82 | 2 | $self->clear_wrapper; | |||||||||||||||||||||||||||||||
| 83 | 2 | $self->flush; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub _abc { die "not implemented." } | ||||||||||||||||||||||||||||||
|
Subroutine
_abc: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub put { _abc() } | ||||||||||||||||||||||||||||||
|
Subroutine
put: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub pump { _abc() } | ||||||||||||||||||||||||||||||
|
Subroutine
pump: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 90 | sub buffer { _abc() } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 1 | my %ansi_codes = ( | |||||||||||||||||||||||||||||||
| 93 | 1 => q/\x1b\[\d+;\d+H/, # code_position_cursor | ||||||||||||||||||||||||||||||||
| 94 | 3 => q/\x1b\[\?25h/, #code_show_cursor | ||||||||||||||||||||||||||||||||
| 95 | 4 => q/\x1b\x45/, #code_next_line | ||||||||||||||||||||||||||||||||
| 96 | 5 => q/\x1b\[2K/, #code_erase_line | ||||||||||||||||||||||||||||||||
| 97 | 6 => q/\x1b\[K/, #code_erase_start_line | ||||||||||||||||||||||||||||||||
| 98 | 7 => q/\x1b\[\d+;\d+r/, #code_enable_scroll | ||||||||||||||||||||||||||||||||
| 99 | 68 => q/\e\[\??\d+(;\d+)*[A-Za-z]/, #VLZ addon from ytti/oxidized | ||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | # https://github.com/ollyg/Net-CLI-Interact/issues/22 | ||||||||||||||||||||||||||||||||
| 103 | around 'buffer' => sub { | ||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $buffer = ($orig->(@_) || ''); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
&$orig(@_) || ''
MC/DC0%0/1
&$orig(@_) || ''
&$orig(@_)
Truth table0%0/2
A
A= &$orig(@_)
| |||||||||||||||||||||||||||||||||
| 106 | # remove control characters | ||||||||||||||||||||||||||||||||
| 107 | 0 | $buffer =~ s/[\000-\010\013\014\016-\032\034-\037]//g; | |||||||||||||||||||||||||||||||
| 108 | # strip ANSI terminal codes | ||||||||||||||||||||||||||||||||
| 109 | 0 | foreach my $code (sort keys %ansi_codes) { | |||||||||||||||||||||||||||||||
| 110 | 0 | my $to = ''; | |||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $to = "\n" if ($code == 4); # CODE_NEXT_LINE must substitute with '\n' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | 0 | $buffer =~ s/$ansi_codes{$code}/$to/g; | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | 0 | return $buffer; | |||||||||||||||||||||||||||||||
| 115 | 1 | }; | |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | sub DEMOLISH { (shift)->disconnect } | ||||||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | sub do_action { | ||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my ($self, $action) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
do_action: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 121 | 0 | $self->logger->log('transport', 'info', 'callback received for', $action->type); | |||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($action->type eq 'match') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 124 | 0 | my $irs_re = $self->irs_re; | |||||||||||||||||||||||||||||||
| 125 | 0 | my $cont = $action->continuation; | |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | while ($self->pump) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 0 | my $all_buffer = $self->buffer; | |||||||||||||||||||||||||||||||
| 129 | 0 | $self->logger->log('dump', 'debug', "SEEN:\n". $all_buffer); | |||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ($all_buffer =~ m/^(.*$irs_re)(.*)/s) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 0 | $self->stash($self->stash . $1); | |||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $self->buffer($2 || ''); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$2 || ''
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
| |||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($cont and $self->find_match($self->buffer, $cont->first->value)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$cont and $self->find_match($self->buffer, $cont->first->value)
MC/DC0%0/2
$cont and $self->find_match($self->buffer, $cont->first->value)
$cont
$self->find_match($self->buffer, $cont->first->value)
Truth table0%0/3
A and B
A= $contB= $self->find_match($self->buffer, $cont->first->value)
| |||||||||||||||||||||||||||||||||
| 137 | 0 | $self->logger->log('transport', 'debug', 'continuation matched'); | |||||||||||||||||||||||||||||||
| 138 | 0 | $self->buffer(''); | |||||||||||||||||||||||||||||||
| 139 | 0 | $self->put($cont->last->value); | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | elsif (my $hit = $self->find_match($self->buffer, $action->value)) { | ||||||||||||||||||||||||||||||||
| 142 | 0 | $self->logger->log('transport', 'info', | |||||||||||||||||||||||||||||||
| 143 | sprintf 'output matched %s, storing and returning', $hit); | ||||||||||||||||||||||||||||||||
| 144 | 0 | $action->prompt_hit($hit); | |||||||||||||||||||||||||||||||
| 145 | 0 | $action->response_stash($self->stash); | |||||||||||||||||||||||||||||||
| 146 | 0 | $action->response($self->buffer); | |||||||||||||||||||||||||||||||
| 147 | 0 | $self->flush; | |||||||||||||||||||||||||||||||
| 148 | 0 | last; | |||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||
| 150 | else { | ||||||||||||||||||||||||||||||||
| 151 | $self->logger->log('transport', 'debug', "nope, doesn't (yet) match", | ||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | (ref $action->value eq ref [] ? (join '|', @{$action->value}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | : $action->value)); | ||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ($action->type eq 'send') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 158 | 0 | my $command = sprintf $action->value, @{ $action->params }; | |||||||||||||||||||||||||||||||
| 159 | 0 | $self->logger->log('dialogue', 'notice', 'queueing data for send: "'. $command .'"'); | |||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $self->put( $command, ($action->no_ors ? () : $self->ors) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | 1 | 1; | |||||||||||||||||||||||||||||||