Interact/Transport/Wrapper/Base.pm

filter: Statementstmt 36.1% 26 / 72 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 33.3% 5 / 15 Podpod 0.0% 0 / 8 totaltotal 25.6% 31 / 121 CC 12 SCAR 40.5
CC
12
Cov
27%
do_action
132.0
_build_wrapper
6.0
init
2.0
CRAP 57.1
« Interact/Role/Prompt.pm ↑ Summary Interact/ActionSet.pm »
1 package Net::CLI::Interact::Transport::Wrapper::Base;
2 2 $Net::CLI::Interact::Transport::Wrapper::Base::VERSION = '2.400001';
3 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use MooX::Types::MooseLike::Base qw(Int RegexpRef Str Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Time::HiRes qw( sleep );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 with 'Net::CLI::Interact::Role::FindMatch';
9  
10 {
11 package # hide from pause
12 Net::CLI::Interact::Transport::Wrapper::Base::Options;
13 2 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 }
15  
16 2 has 'use_net_telnet_connection' => (
17 is => 'rw',
18 isa => Int,
19 default => quote_sub('0'),
20 );
21  
22 2 has 'irs_re' => (
23 is => 'ro',
24 isa => RegexpRef,
25 default => quote_sub(q{ qr/(?:\015\012|\015|\012)/ }), # first wins
26 );
27  
28 2 has 'ors' => (
29 is => 'rw',
30 isa => Str,
31 default => quote_sub(q{"\n"}),
32 );
33  
34 2 has 'timeout' => (
35 is => 'rw',
36 isa => quote_sub(q{ die "$_[0] is not a posint!" unless $_[0] > 0 }),
37 default => quote_sub('10'),
38 );
39  
40 2 has 'app' => (
41 is => 'lazy',
42 isa => Str,
43 predicate => 1,
44 clearer => 1,
45 );
46  
47 2 has 'stash' => (
48 is => 'rw',
49 isa => Str,
50 default => quote_sub(q{''}),
51 );
52  
53 2 has 'wrapper' => (
54 is => 'lazy',
55 isa => Object,
56 predicate => 'connect_ready',
57 clearer => 1,
58 );
59  
60 sub _build_wrapper {
61 0 ▶ my $self = shift;
Subroutine _build_wrapper: not called CC=2 SCAR=17.9
62 $self->logger->log('transport', 'notice', 'connecting with: ',
63 0 ▶ $self->app, (join ' ', map {($_ =~ m/\s/) ? ("'". $_ ."'") : $_}
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /\s/ ? : 0 0 0
64 $self->runtime_options));
65 # this better be wrapped otherwise it'll blow up
66 };
67  
68 0 ▶sub init { (shift)->wrapper(@_) }
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
69  
70 sub flush {
71 0 ▶ my $self = shift;
Subroutine flush: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my $content = $self->stash . $self->buffer;
73 0 $self->stash('');
74 0 $self->buffer('');
75 0 return $content;
76 }
77  
78 sub disconnect {
79 0 ▶ my $self = shift;
Subroutine disconnect: not called CC=1 SCAR=6.9
Pod undocumented
80 0 $self->clear_wrapper;
81 0 $self->flush;
82 }
83  
84 0 ▶sub _abc { die "not implemented." }
Subroutine _abc: not called CC=1 SCAR=6.9
85  
86 0 ▶sub put { _abc() }
Subroutine put: not called CC=1 SCAR=6.9
Pod undocumented
87 0 ▶sub pump { _abc() }
Subroutine pump: not called CC=1 SCAR=6.9
Pod undocumented
88 0 ▶sub buffer { _abc() }
Subroutine buffer: not called CC=1 SCAR=6.9
Pod undocumented
89  
90 0 ▶sub DEMOLISH { (shift)->disconnect }
Subroutine DEMOLISH: not called CC=1 SCAR=6.9
Pod undocumented
91  
92 sub do_action {
93 0 ▶ my ($self, $action) = @_;
Subroutine do_action: not called CC=11 SCAR=48.8
Pod undocumented
94 0 $self->logger->log('transport', 'info', 'callback received for', $action->type);
95  
96 0 ▶ if ($action->type eq 'match') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action->type eq "match") 0 0 0
97 0 my $irs_re = $self->irs_re;
98 0 my $cont = $action->continuation;
99  
100 0 ▶ while ($self->pump) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->pump) 0 0 0
101 # remove control characters
102 0 (my $buffer = $self->buffer) =~ s/[\000-\010\013\014\016-\032\034-\037]//g;
103 0 $self->logger->log('dump', 'debug', "SEEN:\n'". $buffer. "'");
104  
105 0 ▶ if ($buffer =~ m/^(.*$irs_re)(.*)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ /^(.*$irs_re)(.*)/s) 0 0 0
106 0 $self->stash($self->stash . $1);
107 0 ▶ $self->buffer($2 || '');
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
108 }
109  
110 0 ▶ if ($cont and $self->find_match($self->buffer, $cont->first->value)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cont and $self->find_match($self->buffer, $cont->first->value)) { } 0 0 0
elsif (my $hit = $self->find_match($self->buffer, $action->value)) { } 0 0 0
Condition0%0/3
$cont and $self->find_match($self->buffer, $cont->first->value)
!ll&&!rl&&r
000
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)
ABresult
0X0
100
111
111 0 $self->logger->log('transport', 'debug', 'continuation matched');
112 0 $self->buffer('');
113 0 $self->put($cont->last->value);
114 }
115 elsif (my $hit = $self->find_match($self->buffer, $action->value)) {
116 0 $self->logger->log('transport', 'info',
117 sprintf 'output matched %s, storing and returning', $hit);
118 0 $action->prompt_hit($hit);
119 0 $action->response_stash($self->stash);
120 0 $action->response($self->buffer);
121 0 $self->flush;
122 0 last;
123 }
124 else {
125 $self->logger->log('transport', 'debug', "nope, doesn't (yet) match",
126 0 ▶ (ref $action->value eq ref [] ? (join '|', @{$action->value})
Branch: 1 branch
BranchTrueFalseTotal
ref $action->value eq ref [] ? : 0 0 0
127 : $action->value));
128 }
129  
130 0 sleep(0.01);
131 }
132 }
133 0 ▶ if ($action->type eq 'send') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action->type eq "send") 0 0 0
134 0 my $command = sprintf $action->value, @{ $action->params };
135 0 $self->logger->log('dialogue', 'notice', 'queueing data for send: "'. $command .'"');
136 0 ▶ $self->put( $command, ($action->no_ors ? () : $self->ors) );
Branch: 1 branch
BranchTrueFalseTotal
$action->no_ors ? : 0 0 0
137 }
138 }
139  
140 =pod
141  
142 =begin Pod::Coverage
143  
144 DEMOLISH
145 buffer
146 connect_ready
147 disconnect
148 do_action
149 flush
150 has_app
151 init
152 irs_re
153 pump
154 put
155  
156 =end Pod::Coverage
157  
158 =cut
159  
160 2 1;
« Interact/Role/Prompt.pm ↑ Summary Interact/ActionSet.pm »