lib/DR/Tnt/LowLevel/Connector/Sync.pm

filter: Statementstmt 33.3% 22 / 66 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 46.1% 6 / 13 Podpod 0.0% 0 / 1 totaltotal 25.9% 28 / 108 SCAR 44.6
CC
13
Cov
24%
_wait_something
42.0
_connect
20.0
send_pkt
20.0
CRAP 86.7
« blib/lib/DR/Tnt/LowLevel/Connector/Sync.pm ↑ Summary blib/lib/DR/Tnt/LowLevel/Connector/AE.pm »
1 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package DR::Tnt::LowLevel::Connector::Sync;
6 3 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use IO::Socket::UNIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 extends 'DR::Tnt::LowLevel::Connector';
11  
12 sub _connect {
13 0 ▶ my ($self, $cb) = @_;
Subroutine _connect: not called CC=4 SCAR=30.0
14  
15 0 my $fh;
16 0 ▶ if ($self->host eq 'unix' or $self->host eq 'unix/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->host eq 'unix' or $self->host eq 'unix/') { } 0 0 0
Condition0%0/3
$self->host eq "unix" or $self->host eq "unix/"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->host eq "unix" or $self->host eq "unix/"
$self->host eq "unix" $self->host eq "unix/"
Truth table0%0/3
A or B
A= $self->host eq "unix"B= $self->host eq "unix/"
ABresult
1X1
011
000
17 0 $fh = IO::Socket::UNIX->new(
18 Type => SOCK_STREAM,
19 Peer => $self->port,
20 );
21 } else {
22 0 $fh = IO::Socket::INET->new(
23 PeerHost => $self->host,
24 PeerPort => $self->port,
25 Proto => 'tcp',
26 );
27 }
28  
29 0 ▶ unless ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh) 0 0 0
30 0 $cb->(ER_SOCKET => $!);
31 0 return;
32 }
33  
34 0 $self->_set_fh($fh);
35 0 $cb->(OK => 'Socket connected');
36  
37 0 return;
38 }
39
40 sub _handshake {
41 0 ▶ my ($self, $cb) = @_;
Subroutine _handshake: not called CC=1 SCAR=6.9
42 $self->sread(128, sub {
43 0 ▶ my ($state, $message, $hs) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
44 0 ▶ unless ($state eq 'OK') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state eq "OK") 0 0 0
45 0 pop;
46 0 goto \&$cb;
47 }
48 0 $cb->(OK => 'handshake was read', $hs);
49 0 });
50 }
51  
52 sub send_pkt {
53 0 ▶ my ($self, $pkt, $cb) = @_;
Subroutine send_pkt: not called CC=4 SCAR=30.0
Pod undocumented
54  
55 0 while (1) {
56 0 my $done = syswrite $self->fh, $pkt;
57 0 ▶ unless (defined $done) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $done) 0 0 0
58 0 $cb->(ER_SOCKET => $!);
59 0 return;
60 }
61 0 ▶ if ($done == length $pkt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done == length $pkt) 0 0 0
62 0 $cb->(OK => 'swrite done');
63 0 return;
64 }
65 0 ▶ substr $pkt, 0, $done, '' if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
66 }
67 }
68  
69 sub _wait_something {
70 0 ▶ my ($self) = @_;
Subroutine _wait_something: not called CC=6 SCAR=37.4
71 0 ▶ return unless $self->fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->fh 0 0 0
72  
73 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->check_rbuf or do { do { my $blob = ""; my $done = sysread($self->fh, $blob, 4096); unless ($done) { unless (defined $done) { $self->socket_error($! // "Connection lost"); return; } ; $self->socket_error("Remote host closed connection"); return; } ; $self->rbuf($self->rbuf . $blob) } } 0 0 0
74 0 my $blob = '';
75 0 my $done = sysread $self->fh, $blob, 4096;
76  
77 0 ▶ unless ($done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 0 0 0
78 0 ▶ unless (defined $done) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $done) 0 0 0
79 0 ▶ $self->socket_error($! // 'Connection lost');
Condition0%0/2
$! // "Connection lost"
l!l
00
MC/DC0%0/1
$! // "Connection lost"
$!
Truth table0%0/2
A
A= $!
Aresult
11
00
80 0 return;
81 }
82 0 $self->socket_error('Remote host closed connection');
83 0 return;
84 }
85 0 $self->rbuf($self->rbuf . $blob);
86  
87 } until $self->check_rbuf;
88 }
89  
90 after handshake => sub {
91 0 ▶ my ($self) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 $self->_wait_something;
93 3 };
94  
95 after wait_response => sub {
96 0 ▶ my ($self) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 0 $self->_wait_something;
98 3 };
99  
100 3 __PACKAGE__->meta->make_immutable;
« blib/lib/DR/Tnt/LowLevel/Connector/Sync.pm ↑ Summary blib/lib/DR/Tnt/LowLevel/Connector/AE.pm »