blib/lib/Punk/Test/WS/Conn.pm

filter: Statementstmt 94.4% 51 / 54 Branchbran 75.0% 12 / 16 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 76.9% 10 / 13 Podpod 100% 6 / 6 totaltotal 82.3% 84 / 102 CC 12 SCAR 12.7
CC
12
Cov
86%
read_frame
7.6
read_headers
3.0
close
3.0
CRAP 3.6
« blib/lib/Punk/Plugin/RequestId.pm ↑ Summary t/lib/Punk/Command/Fakecmd.pm »
1 package Punk::Test::WS::Conn;
2  
3 35 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use Punk::Test::WS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 35 our $VERSION = '0.69';
9  
10 6 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
11 6 my ($class, %a) = @_;
12 return bless {
13 sock => $a{sock},
14 timeout => $a{timeout} // 5,
15 buf => '',
16 pid => $a{pid},
17 6 ▶ }, $class;
Condition50%1/2
$a{"timeout"} // 5
l!l
60
MC/DC0%0/1
$a{"timeout"} // 5
$a{"timeout"}
Truth table50%1/2
A
A= $a{"timeout"}
Aresult
11
00
18 }
19  
20 0 ▶sub sock { $_[0]{sock} }
Subroutine sock: not called CC=1 SCAR=6.9
Pod documented
21  
22 6 ▶sub read_headers {
Subroutine read_headers: called CC=3 SCAR=11.1
Pod documented
23 6 my ($self) = @_;
24 6 my $buf = '';
25 6 eval {
26 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
27 6 alarm $self->{timeout};
28 6 ▶ while (sysread $self->{sock}, my $c, 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread $self->{"sock"}, my $c, 1) 591 0 591
29 591 $buf .= $c;
30 591 ▶ last if $buf =~ /\r\n\r\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $buf =~ /\r\n\r\n\z/ 6 585 591
31 }
32 6 alarm 0;
33 };
34 6 return $buf;
35 }
36  
37 10 ▶sub send_frame {
Subroutine send_frame: called CC=1 SCAR=0.0
Pod documented
38 10 my ($self, %a) = @_;
39 10 return syswrite $self->{sock}, Punk::Test::WS::encode_client(%a);
40 }
41  
42 10 ▶sub read_frame {
Subroutine read_frame: called CC=7 SCAR=20.2
Pod documented
43 10 my ($self) = @_;
44 10 my $f;
45 10 eval {
46 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
47 10 alarm $self->{timeout};
48 10 while (1) {
49 20 $f = Punk::Test::WS::decode_ref($self->{buf});
50 20 ▶ if ($f && ref $f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f and ref $f) 10 10 20
Condition66%2/3
$f and ref $f
!ll&&!rl&&r
10010
MC/DC50%1/2
$f and ref $f
$f ref $f
Truth table66%2/3
A and B
A= $fB= ref $f
ABresult
0X0
100
111
51 10 substr $self->{buf}, 0, $f->{consumed}, '';
52 10 last;
53 }
54 10 ▶ die "ws protocol error: $f\n" if defined $f && !ref $f;
Branch: 1 branch
BranchTrueFalseTotal
if defined $f and not ref $f 0 10 10
Condition33%1/3
defined $f and not ref $f
!ll&&!rl&&r
1000
MC/DC0%0/2
defined $f and not ref $f
defined $f not ref $f
Truth table33%1/3
A and not(B)
A= defined $fB= not ref $f
ABresult
0X0
100
111
55 10 my $n = sysread $self->{sock}, my $c, 4096;
56 10 ▶ last unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 10 10
57 10 $self->{buf} .= $c;
58 }
59 10 alarm 0;
60 };
61 10 ▶ return ref $f ? $f : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $f ? : 10 0 10
62 }
63  
64 12 ▶sub close {
Subroutine close: called CC=3 SCAR=11.0
Pod documented
65 12 my ($self) = @_;
66 12 ▶ close $self->{sock} if $self->{sock};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"sock"} 6 6 12
67 12 $self->{sock} = undef;
68 12 ▶ if ($self->{pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pid"}) 5 7 12
69 5 waitpid $self->{pid}, 0;
70 5 $self->{pid} = undef;
71 }
72 12 return;
73 }
74  
75 6 ▶sub DESTROY { $_[0]->close }
Subroutine DESTROY: called CC=1 SCAR=0.0
76  
77 35 1;
78  
79 __END__
« blib/lib/Punk/Plugin/RequestId.pm ↑ Summary t/lib/Punk/Command/Fakecmd.pm »