Any/Test/Isolated/_Base.pm

filter: Statementstmt 94.0% 63 / 67 Branchbran 68.7% 11 / 16 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 93.7% 15 / 16 Podpod n/a totaltotal 85.1% 92 / 108 CC 12 SCAR 10.6
CC
12
Cov
87%
_recv_packet
6.2
_deserialize
4.2
_debug
2.1
CRAP 2.9
« Any/Test/Backend/Cygwin.pm ↑ Summary Any/Test/Isolated/_Slave.pm »
1 package Net::SSH::Any::Test::Isolated::_Base;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use feature 'say';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶BEGIN { *debug = \$Net::SSH::Any::Test::Isolated::debug }
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 our $debug;
11  
12 147 ▶sub _debug {
Subroutine _debug: called CC=2 SCAR=7.2
13 147 my $self = shift;
14 147 ▶ print STDERR "$self->{side}> " . join(': ', @_) . "\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::SSH::Any::Test::Isolated::_Base::debug 0 147 147
15 }
16  
17 6 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
18 6 my ($class, $side, $in, $out) = @_;
19 6 my $self = { side => $side,
20 in => $in,
21 out => $out,
22 state => 'new'};
23 6 bless $self, $class;
24 }
25  
26 49 ▶sub _send {
Subroutine _send: called CC=1 SCAR=0.0
27 49 my ($self, $packet) = @_;
28 49 $self->_debug(send => $packet);
29 49 say {$self->{out}} $packet;
30 }
31  
32 46 ▶sub _recv {
Subroutine _recv: called CC=2 SCAR=7.0
33 46 my $self = shift;
34 46 $self->_debug("waiting for data");
35 46 my $in = $self->{in};
36 46 ▶ my $packet = <$in> // return;
Condition50%1/2
readline $in // (return)
l!l
460
MC/DC0%0/1
readline $in // (return)
readline $in
Truth table50%1/2
A
A= readline $in
Aresult
11
00
37 46 $packet =~ s/[\r\n]+$//;
38 46 $self->_debug(recv => $packet);
39 46 $packet;
40 }
41  
42 31 ▶sub _serialize {
Subroutine _serialize: called CC=1 SCAR=0.0
43 31 my $self = shift;
44 31 my $dump = Data::Dumper->new([\@_], ['D']);
45 31 $dump->Terse(1)->Indent(0)->Useqq(1);
46 31 my $data = $dump->Dump;
47 # $self->_debug("serialized $data");
48 31 $data;
49 }
50  
51 31 ▶sub _deserialize {
Subroutine _deserialize: called CC=4 SCAR=14.2
52 31 my $self = shift;
53 31 my ($r, $err);
54 31 do {
55 31 local ($@, $SIG{__DIE__});
56 #$self->_debug("deserializing $_[0]");
57 31 ▶ $r = eval $_[0] // [];
Condition50%1/2
eval $_[0] // []
l!l
310
MC/DC0%0/1
eval $_[0] // []
eval $_[0]
Truth table50%1/2
A
A= eval $_[0]
Aresult
11
00
58 31 $err = $@;
59 };
60 31 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 31 31
61 # $self->_debug("deserialized args", Dumper($r));
62 31 ▶ wantarray ? @$r : $r->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 31 0 31
63 }
64  
65 30 ▶sub _recv_packet {
Subroutine _recv_packet: called CC=6 SCAR=18.3
66 30 my $self = shift;
67 30 while (1) {
68 46 ▶ my $packet = $self->_recv // return;
Condition50%1/2
$self->_recv // (return)
l!l
460
MC/DC0%0/1
$self->_recv // (return)
$self->_recv
Truth table50%1/2
A
A= $self->_recv
Aresult
11
00
69 46 ▶ if (my ($head, $args) = $packet =~ /^(\w+):\s+(.*)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (() = $packet =~ /^(\w+):\s+(.*)$/) { } 31 15 46
elsif ($packet =~ /^\w+!$/) { } 12 3 15
elsif ($packet =~ /^\s*(?:#.*)?$/) { } 3 0 3
70 31 my @args = $self->_deserialize($args);
71 31 ▶ if ($head eq 'log') {
Branch: 1 branch
BranchTrueFalseTotal
if ($head eq "log") 13 18 31
72 13 $self->_log(@args);
73 13 redo;
74 }
75 18 return ($head, @args);
76 }
77 elsif ($packet =~ /^\w+!$/) {
78 12 return $packet
79 }
80 elsif ($packet =~ /^\s*(?:#.*)?$/) {
81 # Ignore blank lines and comments.
82 }
83 else {
84 0 $self->_debug("unexpected data packet: $packet");
85 0 die "Internal error: unexpected data packet $packet";
86 }
87 }
88 }
89  
90 31 ▶sub _send_packet {
Subroutine _send_packet: called CC=1 SCAR=0.0
91 31 my $self = shift;
92 31 my $head = shift;
93 31 my $args = $self->_serialize(@_);
94 31 $self->_send("$head: $args");
95 }
96  
97 0 ▶sub _log {
Subroutine _log: not called CC=1 SCAR=6.9
98 0 my $self = shift;
99 0 print STDERR join(': ', log => @_);
100 }
101  
102 15 ▶sub _check_state {
Subroutine _check_state: called CC=2 SCAR=7.2
103 15 my ($self, $state) = @_;
104 15 ▶ $self->{state} eq $state or croak "invalid state for action, current state: $self->{state}, expected: $state";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"state"} eq $state or croak(qq[invalid state for action, current state: $self->{"state"}, expected: $state]) 15 0 15
105 }
106  
107 4 1;
« Any/Test/Backend/Cygwin.pm ↑ Summary Any/Test/Isolated/_Slave.pm »