WebSocket/Handshake/Client.pm

filter: Statementstmt 92.7% 51 / 55 Branchbran 86.3% 19 / 22 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 92.3% 12 / 13 Podpod 83.3% 5 / 6 totaltotal 86.7% 92 / 106 CC 14 SCAR 13.2
CC
14
Cov
89%
parse
6.4
_set_url
6.0
new
3.0
CRAP 3.7
« WebSocket/Cookie/Request.pm ↑ Summary WebSocket/Client.pm »
1 package Protocol::WebSocket::Handshake::Client;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use base 'Protocol::WebSocket::Handshake';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 require Carp;
9  
10 5 ▶use Protocol::WebSocket::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Protocol::WebSocket::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 19 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
14 19 my $self = shift->SUPER::new(@_);
15  
16 19 ▶ $self->_set_url($self->{url}) if defined $self->{url};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"url"} 13 6 19
17  
18 19 ▶ if (my $version = $self->{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $version = $self->{"version"}) 5 14 19
19 5 $self->req->version($version);
20 5 $self->res->version($version);
21 }
22  
23 19 return $self;
24 }
25  
26 4 ▶sub url {
Subroutine url: called CC=2 SCAR=7.0
Pod documented
27 4 my $self = shift;
28 4 my $url = shift;
29  
30 4 ▶ return $self->{url} unless $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 0 4 4
31  
32 4 $self->_set_url($url);
33  
34 4 return $self;
35 }
36  
37 18 ▶sub parse {
Subroutine parse: called CC=6 SCAR=18.5
Pod documented
38 18 my $self = shift;
39  
40 18 my $req = $self->req;
41 18 my $res = $self->res;
42  
43 18 ▶ unless ($res->is_done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_done) 18 0 18
44 18 ▶ unless ($res->parse($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->parse($_[0])) 2 16 18
45 2 $self->error($res->error);
46 2 return;
47 }
48  
49 16 ▶ if ($res->is_done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_done) 6 10 16
50 6 ▶ if ( $req->version eq 'draft-ietf-hybi-00'
Branch: 1 branch
BranchTrueFalseTotal
if ($req->version eq "draft-ietf-hybi-00" and $req->checksum ne $res->checksum) 0 6 6
Condition66%2/3
$req->version eq "draft-ietf-hybi-00" and $req->checksum ne $res->checksum
!ll&&!rl&&r
420
MC/DC0%0/2
$req->version eq "draft-ietf-hybi-00" and $req->checksum ne $res->checksum
$req->version eq "draft-ietf-hybi-00" $req->checksum ne $res->checksum
Truth table66%2/3
A and B
A= $req->version eq "draft-ietf-hybi-00"B= $req->checksum ne $res->checksum
ABresult
0X0
100
111
51 && $req->checksum ne $res->checksum)
52 {
53 0 $self->error('Checksum is wrong.');
54 0 return;
55 }
56 }
57 }
58  
59 16 return 1;
60 }
61  
62 15 ▶sub is_done { shift->res->is_done }
Subroutine is_done: called CC=1 SCAR=0.0
Pod documented
63 9 ▶sub to_string { shift->req->to_string }
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
64  
65 0 ▶sub build_frame {
Subroutine build_frame: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my $self = shift;
67  
68 0 return Protocol::WebSocket::Frame->new(masked => 1, version => $self->version, @_);
69 }
70  
71 8 ▶sub _build_url { Protocol::WebSocket::URL->new }
Subroutine _build_url: called CC=1 SCAR=0.0
72  
73 17 ▶sub _set_url {
Subroutine _set_url: called CC=6 SCAR=17.9
74 17 my $self = shift;
75 17 my $url = shift;
76  
77 17 ▶ $url = $self->_build_url->parse($url) unless ref $url;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $url 8 9 17
78  
79 17 ▶ $self->req->secure(1) if $url->secure;
Branch: 1 branch
BranchTrueFalseTotal
if $url->secure 3 14 17
80  
81 17 my $req = $self->req;
82  
83 17 my $host = $url->host;
84 17 ▶ $host .= ':' . $url->port
Branch: 2 branches
BranchTrueFalseTotal
if defined $url->port and $url->secure ? $url->port ne 443 : $url->port ne 80 9 8 17
$url->secure ? : 3 14 17
Condition66%2/3
defined $url->port and $url->secure ? $url->port ne 443 : $url->port ne 80
!ll&&!rl&&r
089
MC/DC50%1/2
defined $url->port and $url->secure ? $url->port ne 443 : $url->port ne 80
defined $url->port $url->secure ? $url->port ne 443 : $url->port ne 80
Truth table66%2/3
A and B
A= defined $url->portB= $url->secure ? $url->port ne 443 : $url->port ne 80
ABresult
0X0
100
111
85 if defined $url->port
86 && ($url->secure ? $url->port ne '443' : $url->port ne '80');
87 17 $req->host($host);
88  
89 17 $req->resource_name($url->resource_name);
90  
91 17 return $self;
92 }
93  
94 5 1;
95 __END__
« WebSocket/Cookie/Request.pm ↑ Summary WebSocket/Client.pm »