| 1 | package Punk::Test::WS::Conn; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 56 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 56 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 56 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 56 | ▶ | use Punk::Test::WS (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 56 | our $VERSION = '0.70'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 45 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 45 | my ($class, %a) = @_; | |||||||||||||||||||||||||||
| 12 | return bless { | ||||||||||||||||||||||||||||
| 13 | sock => $a{sock}, | ||||||||||||||||||||||||||||
| 14 | timeout => $a{timeout} // 5, | ||||||||||||||||||||||||||||
| 15 | buf => '', | ||||||||||||||||||||||||||||
| 16 | pid => $a{pid}, | ||||||||||||||||||||||||||||
| 17 | # uncoverable condition right | ||||||||||||||||||||||||||||
| 18 | 45 | ▶ | }, $class; | ||||||||||||||||||||||||||
|
Condition100%1/2
$a{"timeout"} // 5
MC/DC100%0/1
$a{"timeout"} // 5
$a{"timeout"}
Truth table100%1/2
A
A= $a{"timeout"}
| |||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | sub sock { $_[0]{sock} } | ||||||||||||||||||||||||||
|
Subroutine
sock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 45 | ▶ | sub read_headers { | ||||||||||||||||||||||||||
|
Subroutine
read_headers: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 45 | my ($self) = @_; | |||||||||||||||||||||||||||
| 25 | 45 | my $buf = ''; | |||||||||||||||||||||||||||
| 26 | 45 | eval { | |||||||||||||||||||||||||||
| 27 | # uncoverable subroutine | ||||||||||||||||||||||||||||
| 28 | # uncoverable statement count:2 | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | local $SIG{ALRM} = sub { die "timeout\n" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called (uncoverable) CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 45 | alarm $self->{timeout}; | |||||||||||||||||||||||||||
| 31 | 45 | ▶ | while (sysread $self->{sock}, my $c, 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 5044 | $buf .= $c; | |||||||||||||||||||||||||||
| 33 | 5044 | ▶ | last if $buf =~ /\r\n\r\n\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 45 | alarm 0; | |||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||
| 37 | 45 | return $buf; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 62 | ▶ | sub send_frame { | ||||||||||||||||||||||||||
|
Subroutine
send_frame: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 62 | my ($self, %a) = @_; | |||||||||||||||||||||||||||
| 42 | 62 | return syswrite $self->{sock}, Punk::Test::WS::encode_client(%a); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 73 | ▶ | sub read_frame { | ||||||||||||||||||||||||||
|
Subroutine
read_frame: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 73 | my ($self) = @_; | |||||||||||||||||||||||||||
| 47 | 73 | my $f; | |||||||||||||||||||||||||||
| 48 | 73 | eval { | |||||||||||||||||||||||||||
| 49 | 73 | ▶ | local $SIG{ALRM} = sub { die "timeout\n" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 73 | alarm $self->{timeout}; | |||||||||||||||||||||||||||
| 51 | 73 | while (1) { | |||||||||||||||||||||||||||
| 52 | 143 | $f = Punk::Test::WS::decode_ref($self->{buf}); | |||||||||||||||||||||||||||
| 53 | # uncoverable condition right | ||||||||||||||||||||||||||||
| 54 | 143 | ▶ | if ($f && ref $f) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
$f and ref $f
MC/DC100%1/2
$f and ref $f
$f
ref $f
Truth table100%2/3
A and B
A= $fB= ref $f
| |||||||||||||||||||||||||||||
| 55 | 70 | substr $self->{buf}, 0, $f->{consumed}, ''; | |||||||||||||||||||||||||||
| 56 | 70 | last; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | # uncoverable branch true | ||||||||||||||||||||||||||||
| 59 | # uncoverable condition right | ||||||||||||||||||||||||||||
| 60 | # uncoverable condition false | ||||||||||||||||||||||||||||
| 61 | 73 | ▶ | die "ws protocol error: $f\n" if defined $f && !ref $f; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
defined $f and not ref $f
MC/DC100%0/2
defined $f and not ref $f
defined $f
not ref $f
Truth table100%1/3
A and not(B)
A= defined $fB= not ref $f
| |||||||||||||||||||||||||||||
| 62 | 73 | my $n = sysread $self->{sock}, my $c, 4096; | |||||||||||||||||||||||||||
| 63 | # uncoverable branch true | ||||||||||||||||||||||||||||
| 64 | 70 | ▶ | last unless $n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 70 | $self->{buf} .= $c; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 70 | alarm 0; | |||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||
| 69 | 73 | ▶ | return ref $f ? $f : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 90 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 90 | my ($self) = @_; | |||||||||||||||||||||||||||
| 74 | 90 | ▶ | close $self->{sock} if $self->{sock}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 90 | $self->{sock} = undef; | |||||||||||||||||||||||||||
| 76 | 90 | ▶ | if ($self->{pid}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 43 | waitpid $self->{pid}, 0; | |||||||||||||||||||||||||||
| 78 | 43 | $self->{pid} = undef; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 90 | return; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 45 | ▶ | sub DESTROY { $_[0]->close } | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 56 | 1; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||