| 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
MC/DC0%0/1
$a{"timeout"} // 5
$a{"timeout"}
Truth table50%1/2
A
A= $a{"timeout"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 29 | 591 | $buf .= $c; | |||||||||||||||||||||||||||
| 30 | 591 | ▶ | last if $buf =~ /\r\n\r\n\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$f and ref $f
MC/DC50%1/2
$f and ref $f
$f
ref $f
Truth table66%2/3
A and B
A= $fB= ref $f
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $f and not ref $f
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
| |||||||||||||||||||||||||||||
| 55 | 10 | my $n = sysread $self->{sock}, my $c, 4096; | |||||||||||||||||||||||||||
| 56 | 10 | ▶ | last unless $n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 10 | $self->{buf} .= $c; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 10 | alarm 0; | |||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||
| 61 | 10 | ▶ | return ref $f ? $f : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 67 | 12 | $self->{sock} = undef; | |||||||||||||||||||||||||||
| 68 | 12 | ▶ | if ($self->{pid}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||