Any/Test/Isolated/_Slave.pm

filter: Statementstmt 76.8% 63 / 82 Branchbran 50.0% 6 / 12 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 78.9% 15 / 19 Podpod 0.0% 0 / 1 totaltotal 71.6% 86 / 120 CC 9 SCAR 9.2
CC
9
Cov
72%
_do_forward
6.0
_run
5.3
__logger
2.2
CRAP 2.5
« Any/Test/Isolated/_Base.pm ↑ Summary Any/Backend/Net_OpenSSH/DPipe.pm »
1 package Net::SSH::Any::Test::Isolated::_Slave;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 $0 = "$^X (Net::SSH::Any::Test::Isolated::Slave)";
9 3 binmode STDOUT;
10 3 binmode STDIN;
11 3 $| = 1;
12  
13 3 ▶use parent 'Net::SSH::Any::Test::Isolated::_Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶BEGIN { *debug = \$Net::SSH::Any::Test::Isolated::debug };
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 our $debug;
16  
17 3 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
18 3 my $class = shift;
19 3 $class->_new(@_)->_run;
20 }
21  
22 3 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
23 3 my $class = shift;
24 3 $class->SUPER::_new('slave', \*STDIN, \*STDOUT);
25 }
26  
27 3 ▶sub _run {
Subroutine _run: called CC=5 SCAR=16.6
28 3 my $self = shift;
29 3 while (1) {
30 12 $self->_send_prompt;
31 12 ▶ if (my ($head, @args) = $self->_recv_packet) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $self->_recv_packet) 12 0 12
32 12 ▶ unless ($head eq 'close!') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($head eq "close!") 9 3 12
33 9 ▶ if (my $method = $self->can("_do_$head")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->can("_do_$head")) { } 9 0 9
34 #$self->_debug("calling $method(@args)");
35 9 my @r = eval { $self->$method(@args) };
36 9 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 9 9
37 0 $self->_send_packet(exception => $@)
38 }
39 else {
40 9 $self->_send_packet(response => @r)
41 }
42 }
43 else {
44 0 $self->_send_packet(exception => "Internal error: invalid method $head");
45 }
46 9 next;
47 }
48 }
49  
50 # connection closed;
51 3 $self->_debug("connection closed");
52 3 return;
53 }
54 }
55  
56 12 ▶sub _send_prompt { shift->_send('go!') }
Subroutine _send_prompt: called CC=1 SCAR=0.0
57  
58 13 ▶sub __logger {
Subroutine __logger: called CC=2 SCAR=7.9
59 13 my $self = shift;
60 13 my $fh = shift;
61 13 ▶ if ($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) { } 13 0 13
62 13 $self->_send_packet(log => @_);
63 }
64 else {
65 0 print {$fh} @_
66 }
67 }
68  
69 3 ▶sub _do_start {
Subroutine _do_start: called CC=2 SCAR=6.9
70 3 my ($self, @opts) = @_;
71 3 $self->_check_state('new');
72 3 require Net::SSH::Any::Test;
73  
74 3 open my($logger_fh), '>', File::Spec->devnull;
75 3 ▶ $logger_fh //= \*STDERR; # Just in case!
Condition50%1/2
$logger_fh //= \*STDERR
l!l
30
MC/DC0%0/1
$logger_fh //= \*STDERR
$logger_fh
Truth table50%1/2
A
A= $logger_fh
Aresult
11
00
76  
77 3 my $weak_self = $self;
78 3 Scalar::Util::weaken($weak_self);
79 $self->{tssh} = Net::SSH::Any::Test->new(@opts,
80 logger_fh => $logger_fh,
81 3 ▶ logger => sub { __logger($weak_self, @_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
82 3 $self->{state} = 'running';
83 3 1;
84 }
85  
86 0 ▶sub _do_forward {
Subroutine _do_forward: not called CC=2 SCAR=17.9
87 0 my $self = shift;
88 0 my $method = shift;
89 0 my $wantarray = shift;
90 0 $self->_check_state('running');
91 0 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) { } 0 0 0
92 0 return $self->{tssh}->$method(@_);
93 }
94 else {
95 0 return scalar $self->{tssh}->$method(@_);
96 }
97 }
98  
99 0 ▶sub _do_peek {
Subroutine _do_peek: not called CC=1 SCAR=6.9
100 0 my ($self, $key) = @_;
101 0 $self->_check_state('running');
102 0 $self->{tssh}{$key};
103 }
104  
105 0 ▶sub _do_poke {
Subroutine _do_poke: not called CC=1 SCAR=6.9
106 0 my ($self, $key, $value) = @_;
107 0 $self->_check_state('running');
108 0 $self->{tssh}{$key} = $value;
109 }
110  
111 0 ▶sub _do_eval {
Subroutine _do_eval: not called CC=1 SCAR=6.9
112 0 my ($self, $code) = @_;
113 0 eval $code;
114 }
115  
116 3 ▶sub _do_stop {
Subroutine _do_stop: called CC=1 SCAR=0.0
117 3 my $self = shift;
118 3 $self->_check_state('running');
119 3 undef $self->{tssh};
120 3 $self->{state} = 'stopped';
121 }
122  
123 3 ▶sub _do_error {
Subroutine _do_error: called CC=2 SCAR=7.0
124 3 my $self = shift;
125 3 $self->_check_state('running');
126 3 ▶ my $error = $self->{tssh}->error // return;
Condition50%1/2
$self->{"tssh"}->error // (return)
l!l
30
MC/DC0%0/1
$self->{"tssh"}->error // (return)
$self->{"tssh"}->error
Truth table50%1/2
A
A= $self->{"tssh"}->error
Aresult
11
00
127 3 return ($error + 0, $error);
128 }
129  
130 3 1;
« Any/Test/Isolated/_Base.pm ↑ Summary Any/Backend/Net_OpenSSH/DPipe.pm »