WebSocket/Response.pm

filter: Statementstmt 44.9% 170 / 378 Branchbran 15.7% 45 / 286 Conditioncond 18.6% 37 / 198 MC/DCmcdc 4.0% 4 / 100 Subroutinesub 63.4% 33 / 52 Podpod 100% 19 / 19 totaltotal 29.8% 308 / 1033 CC 214 SCAR 74.4
CC
214
Cov
29%
parse
3464.3
headers_as_string
2352.0
parse_body
138.9
CRAP 1705.6
« WebSocket/Headers.pm ↑ Summary WebSocket/Request.pm »
1 ##----------------------------------------------------------------------------
2 ## WebSocket Client & Server - ~/lib/WebSocket/Response.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/09/17
7 ## Modified 2021/09/17
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package WebSocket::Response;
14 BEGIN
15 5 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶ use WebSocket::Common qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶ use parent qw( WebSocket::Common );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶ use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶ use HTTP::Response ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶ use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶ use Nice::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶ use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶ use WebSocket::Extension;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶ use WebSocket::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶ use WebSocket::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 # Defined since version 4 of the rfc6455 section 1.3
30 # <https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-04#section-1.3>
31 5 ▶ use constant GUID => '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶ use constant HTTP_SWITCHING_PROTOCOLS => 101;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 our $VERSION = 'v0.1.0';
34 };
35  
36 sub init
37 5 ▶{
Subroutine init: called CC=15 SCAR=36.3
Pod documented
38 5 my $self = shift( @_ );
39 5 my( $code, $status, $headers, $buffer );
40 5 ▶ if( @_ &&
Branch: 2 branches
BranchTrueFalseTotal
if (@_ and $self->_is_array($_[2]) || $self->_is_a($_[2], 'HTTP::Headers')) { } 0 5 5
elsif (@_ and not $self->can($_[0])) { } 1 5 6
Condition50%3/6
@_ and $self->_is_array($_[2]) || $self->_is_a($_[2], "HTTP::Headers")
!ll&&!rl&&r
140
$self->_is_array($_[2]) or $self->_is_a($_[2], "HTTP::Headers")
l!l&&r!l&&!r
004
MC/DC0%0/3
@_ and $self->_is_array($_[2]) || $self->_is_a($_[2], "HTTP::Headers")
@_ $self->_is_array($_[2]) $self->_is_a($_[2], "HTTP::Headers")
Truth table50%2/4
A and B or C
A= @_B= $self->_is_array($_[2])C= $self->_is_a($_[2], "HTTP::Headers")
ABCresult
0XX0
1000
11X1
1011
41 ( $self->_is_array( $_[2] ) || $self->_is_a( $_[2], 'HTTP::Headers' ) ) )
42 {
43 0 ( $code, $status, $headers ) = splice( @_, 0, 3 );
44 0 ▶ if( $self->_is_a( $headers, 'HTTP::Headers' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($headers, 'HTTP::Headers')) { } 0 0 0
45 {
46 0 $headers = $headers->clone;
47 0 $headers = bless( $headers => 'WebSocket::Headers' );
48 }
49 else
50 {
51 0 $headers = WebSocket::Headers->new( @$headers );
52 }
53 # $req->new( 101, 'Switching Protocol', $headers, $buffer, k1 => v1, k2 => v2);
54 # $req->new( 101, 'Switching Protocol', $headers, $buffer, { k1 => v1, k2 => v2 });
55 # $req->new( 101, 'Switching Protocol', $headers, k1 => v1, k2 => v2 );
56 # $req->new( 101, 'Switching Protocol', $headers, { k1 => v1, k2 => v2 });
57 0 ▶ if( ( ( @_ % 2 ) && ref( $_[1] ) ne 'HASH' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH") 0 0 0
Condition0%0/6
@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH"
l!l&&r!l&&!r
000
@_ % 2 and ref $_[1] ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH"
@_ % 2 ref $_[1] ne "HASH" ref $_[1] eq "HASH"
Truth table0%0/5
A and B or C
A= @_ % 2B= ref $_[1] ne "HASH"C= ref $_[1] eq "HASH"
ABCresult
11X1
0X11
1011
0X00
1000
58 ref( $_[1] ) eq 'HASH' )
59 {
60 0 $buffer = shift( @_ );
61 }
62 }
63 # Otherwise, the first parameter is not a known method, so we safely assume this is a code argument
64 ▶ elsif( @_ && !$self->can( $_[0] ) )
Condition100%3/3
@_ and not $self->can($_[0])
!ll&&!rl&&r
131
MC/DC100%2/2
@_ and not $self->can($_[0])
@_ not $self->can($_[0])
Truth table100%3/3
A and not(B)
A= @_B= not $self->can($_[0])
ABresult
0X0
100
111
65 {
66 1 $code = shift( @_ );
67 # possibly followed by a status argument
68 1 ▶ if( ( ( @_ % 2 ) && ref( $_[1] ) ne 'HASH' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH") 1 0 1
Condition33%2/6
@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH"
l!l&&r!l&&!r
100
@_ % 2 and ref $_[1] ne "HASH"
!ll&&!rl&&r
001
MC/DC0%0/3
@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH"
@_ % 2 ref $_[1] ne "HASH" ref $_[1] eq "HASH"
Truth table20%1/5
A and B or C
A= @_ % 2B= ref $_[1] ne "HASH"C= ref $_[1] eq "HASH"
ABCresult
11X1
0X11
1011
0X00
1000
69 ref( $_[1] ) eq 'HASH' )
70 {
71 1 $status = shift( @_ );
72 }
73 }
74 5 $self->{buffer} = $buffer;
75 5 ▶ $self->{code} = $code || HTTP_SWITCHING_PROTOCOLS;
Condition100%2/2
$code || 101
l!l
14
MC/DC100%1/1
$code || 101
$code
Truth table100%2/2
A
A= $code
Aresult
11
00
76 5 $self->{cookies} = [];
77 5 $self->{headers} = $headers;
78 5 $self->{status} = $status;
79 5 $self->{version} = [];
80 5 $self->{_init_strict_use_sub} = 1;
81 5 $self->{_init_params_order} = [qw( buffer headers )];
82 5 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 5 0 5
83 5 return( $self );
84 }
85  
86 sub as_string
87 0 ▶{
Subroutine as_string: not called CC=2 SCAR=17.9
Pod documented
88 0 my $self = shift( @_ );
89 0 ▶ my $eol = shift( @_ ) || "\x0d\x0a";
Condition0%0/2
shift @_ || "\r\n"
l!l
00
MC/DC0%0/1
shift @_ || "\r\n"
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
90 0 my $code = $self->code;
91 0 my $resp_line = "HTTP/1.1 ${code} WebSocket Protocol Handshake";
92 # my $resp_line = "HTTP/1.1 ${code} Switching Protocols";
93 0 return( join( $eol, $resp_line, $self->headers_as_string( $eol ), $self->body_as_string ) );
94 }
95  
96 sub body_as_string
97 0 ▶{
Subroutine body_as_string: not called CC=8 SCAR=42.8
Pod documented
98 0 my $self = shift( @_ );
99 # return( $self->checksum ) if( $self->version eq 'draft-ietf-hybi-00' );
100 0 my $v = $self->version;
101 # checksums are not used on and after version 4 or before hixie version 76
102 # This is not set if this is an error
103 0 ▶ if( $self->code == 101 &&
Branch: 2 branches
BranchTrueFalseTotal
if ($self->code == 101 and $v->type eq 'hybi' && $v->revision < 4 || $v->type eq 'hixie' && $v->revision == 76) { } 0 0 0
elsif ($self->is_error and $self->buffer->length) { } 0 0 0
Condition0%0/12
$self->code == 101 and $v->type eq "hybi" && $v->revision < 4 || $v->type eq "hixie" && $v->revision == 76
!ll&&!rl&&r
000
$v->type eq "hybi" and $v->revision < 4 or $v->type eq "hixie" and $v->revision == 76
l!l&&r!l&&!r
000
$v->type eq "hybi" and $v->revision < 4
!ll&&!rl&&r
000
$v->type eq "hixie" and $v->revision == 76
!ll&&!rl&&r
000
MC/DC0%0/5
$self->code == 101 and $v->type eq "hybi" && $v->revision < 4 || $v->type eq "hixie" && $v->revision == 76
$self->code == 101 $v->type eq "hybi" $v->revision < 4 $v->type eq "hixie" $v->revision == 76
Truth table0%0/8
A and B and C or D and E
A= $self->code == 101B= $v->type eq "hybi"C= $v->revision < 4D= $v->type eq "hixie"E= $v->revision == 76
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
104 (
105 ( $v->type eq 'hybi' && $v->revision < 4 ) ||
106 ( $v->type eq 'hixie' && $v->revision == 76 ) )
107 )
108 {
109 0 return( $self->checksum );
110 }
111 ▶ elsif( $self->is_error && $self->buffer->length )
Condition0%0/3
$self->is_error and $self->buffer->length
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_error and $self->buffer->length
$self->is_error $self->buffer->length
Truth table0%0/3
A and B
A= $self->is_errorB= $self->buffer->length
ABresult
0X0
100
111
112 {
113 0 $self->headers->header( 'Content-Length' => $self->buffer->length->scalar );
114 0 return( $self->buffer->scalar );
115 }
116 0 return( '' );
117 }
118  
119 1 ▶sub code { return( shift->_set_get_number( 'code', @_ ) ); }
Subroutine code: called CC=1 SCAR=0.0
Pod documented
120  
121 0 ▶sub cookies { return( shift->_set_get_array_as_object( 'cookies', @_ ) ); }
Subroutine cookies: not called CC=1 SCAR=6.9
Pod documented
122  
123 0 ▶sub header { return( shift->headers->header( @_ ) ); }
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
124  
125 sub headers_as_string
126 0 ▶{
Subroutine headers_as_string: not called CC=48 SCAR=77.6
Pod documented
127 0 my $self = shift( @_ );
128 0 ▶ my $eol = shift( @_ ) || "\x0d\x0a";
Condition0%0/2
shift @_ || "\r\n"
l!l
00
MC/DC0%0/1
shift @_ || "\r\n"
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
129 # Get the first version available
130 0 ▶ my $version = $self->version || $self->version( WEBSOCKET_DRAFT_VERSION_DEFAULT );
Condition0%0/3
$self->version || $self->version('draft-ietf-hybi-17')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->version || $self->version('draft-ietf-hybi-17')
$self->version $self->version('draft-ietf-hybi-17')
Truth table0%0/3
A || B
A= $self->versionB= $self->version('draft-ietf-hybi-17')
ABresult
1X1
011
000
131 0 my $h = $self->headers;
132 0 my $upgrade = 'WebSocket';
133 # From version 4 onward the value of Upgrade header is all lowercase
134 0 ▶ if( $version->type eq 'hybi' && $version->revision => 4 )
Branch: 2 branches
BranchTrueFalseTotal
if ($version->type eq "hybi" && $version->revision, 4) 0 0 0
$version->type eq "hybi" and $version->revision 0 0 0
135 {
136 0 $upgrade = lc( $upgrade );
137 }
138 $h->header(
139 0 Upgrade => $upgrade,
140 Connection => 'Upgrade',
141 );
142 # return( $self->error( "Host is required" ) ) unless( $self->host->defined );
143 0 ▶ my $location = URI->new( 'ws' . ( $self->secure ? 's' : '' ) . '://' . $self->host );
Branch: 1 branch
BranchTrueFalseTotal
$self->secure ? : 0 0 0
144 0 ▶ $location->path( $self->uri->path ) if( $self->uri && $self->uri->path ne '/' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->uri and $self->uri->path ne "/" 0 0 0
Condition0%0/3
$self->uri and $self->uri->path ne "/"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->uri and $self->uri->path ne "/"
$self->uri $self->uri->path ne "/"
Truth table0%0/3
A and B
A= $self->uriB= $self->uri->path ne "/"
ABresult
0X0
100
111
145 0 ▶ my $origin = URI->new( $self->origin ? $self->origin : 'http://' . $location->host );
Branch: 1 branch
BranchTrueFalseTotal
$self->origin ? : 0 0 0
146 0 ▶ $origin->scheme( 'https' ) if( !$self->origin && $self->secure );
Branch: 1 branch
BranchTrueFalseTotal
if not $self->origin and $self->secure 0 0 0
Condition0%0/3
not $self->origin and $self->secure
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->origin and $self->secure
not $self->origin $self->secure
Truth table0%0/3
not(A) and B
A= not $self->originB= $self->secure
ABresult
0X0
100
111
147  
148 # rfc6455 section 4.2.2 on server handshake response
149 # For draft revision 4 to 17 (latest)
150 0 ▶ if( $version->type eq 'hybi' && $version->revision >= 4 )
Branch: 1 branch
BranchTrueFalseTotal
if ($version->type eq "hybi" and $version->revision >= 4) 0 0 0
Condition0%0/3
$version->type eq "hybi" and $version->revision >= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$version->type eq "hybi" and $version->revision >= 4
$version->type eq "hybi" $version->revision >= 4
Truth table0%0/3
A and B
A= $version->type eq "hybi"B= $version->revision >= 4
ABresult
0X0
100
111
151 {
152 0 ▶ $h->header( 'Sec-WebSocket-Version' => $self->versions->join( ',' )->scalar ) unless( $h->header( 'Sec-WebSocket-Version' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $h->header("Sec-WebSocket-Version") 0 0 0
153 }
154 0 ▶ if( ( $version->type eq 'hybi' && $version->revision >= 0 && $version->revision <= 3 ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($version->type eq 'hybi' and $version->revision >= 0 and $version->revision <= 3 or $version->type eq 'hixie' and $version->revision == 76) { } 0 0 0
Condition0%0/12
$version->type eq "hybi" and $version->revision >= 0 and $version->revision <= 3 or $version->type eq "hixie" and $version->revision == 76
l!l&&r!l&&!r
000
$version->type eq "hybi" and $version->revision >= 0 and $version->revision <= 3
!ll&&!rl&&r
000
$version->type eq "hybi" and $version->revision >= 0
!ll&&!rl&&r
000
$version->type eq "hixie" and $version->revision == 76
!ll&&!rl&&r
000
MC/DC0%0/5
$version->type eq "hybi" and $version->revision >= 0 and $version->revision <= 3 or $version->type eq "hixie" and $version->revision == 76
$version->type eq "hybi" $version->revision >= 0 $version->revision <= 3 $version->type eq "hixie" $version->revision == 76
Truth table0%0/10
A and B and C or D and E
A= $version->type eq "hybi"B= $version->revision >= 0C= $version->revision <= 3D= $version->type eq "hixie"E= $version->revision == 76
ABCDEresult
111XX1
0XX111
10X111
110111
0XX0X0
0XX100
10X0X0
10X100
1100X0
110100
155 ( $version->type eq 'hixie' && $version->revision == 76 ) )
156 {
157 0 ▶ my $loc = URI->new( ( $self->handshake->request->secure ? 'wss://' : 'ws://' ) . $self->handshake->request->host . ( $self->handshake->request->uri->path || '/' ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->handshake->request->secure ? : 0 0 0
Condition0%0/2
$self->handshake->request->uri->path || '/'
l!l
00
MC/DC0%0/1
$self->handshake->request->uri->path || '/'
$self->handshake->request->uri->path
Truth table0%0/2
A
A= $self->handshake->request->uri->path
Aresult
11
00
158 0 $h->header( 'Sec-WebSocket-Location' => $loc );
159 }
160 else
161 {
162 0 $h->remove_header( 'Sec-WebSocket-Location' );
163 }
164
165 0 ▶ if( ( $version->type eq 'hixie' && $version->revision == 76 ) ||
Branch: 3 branches
BranchTrueFalseTotal
if ($version->type eq 'hixie' and $version->revision == 76 or $version->type eq 'hybi' && $version->revision, 0) { } 0 0 0
elsif ($version->type eq 'hixie' and $version->revision <= 75) { } 0 0 0
$version->type eq "hybi" and $version->revision 0 0 0
Condition0%0/6
$version->type eq "hixie" and $version->revision == 76 or $version->type eq "hybi" && $version->revision, 0
l!l&&r!l&&!r
000
$version->type eq "hixie" and $version->revision == 76
!ll&&!rl&&r
000
MC/DC0%0/3
$version->type eq "hixie" and $version->revision == 76 or $version->type eq "hybi" && $version->revision, 0
$version->type eq "hixie" $version->revision == 76 $version->type eq "hybi" && $version->revision, 0
Truth table0%0/5
A and B or C
A= $version->type eq "hixie"B= $version->revision == 76C= $version->type eq "hybi" && $version->revision, 0
ABCresult
11X1
0X11
1011
0X00
1000
166 ( $version->type eq 'hybi' && $version->revision => 0 && $version->revision <= 3 ) )
167 {
168 0 $h->header(
169 'Sec-WebSocket-Origin' => $origin,
170 'Sec-WebSocket-Location' => $location,
171 );
172 }
173 ▶ elsif( $version->type eq 'hixie' && $version->revision <= 75 )
Condition0%0/3
$version->type eq "hixie" and $version->revision <= 75
!ll&&!rl&&r
000
MC/DC0%0/2
$version->type eq "hixie" and $version->revision <= 75
$version->type eq "hixie" $version->revision <= 75
Truth table0%0/3
A and B
A= $version->type eq "hixie"B= $version->revision <= 75
ABresult
0X0
100
111
174 {
175 0 $h->header(
176 'WebSocket-Origin' => $origin,
177 'WebSocket-Location' => $location,
178 );
179 }
180 else
181 {
182 0 $h->remove_header( qw( Sec-WebSocket-Origin WebSocket-Origin Sec-WebSocket-Location WebSocket-Location ) );
183 }
184
185 0 ▶ if( $self->code == 101 && $version->type eq 'hybi' && $version->revision >= 4 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->code == 101 and $version->type eq 'hybi' and $version->revision >= 4) { } 0 0 0
Condition0%0/6
$self->code == 101 and $version->type eq "hybi" and $version->revision >= 4
!ll&&!rl&&r
000
$self->code == 101 and $version->type eq "hybi"
!ll&&!rl&&r
000
MC/DC0%0/3
$self->code == 101 and $version->type eq "hybi" and $version->revision >= 4
$self->code == 101 $version->type eq "hybi" $version->revision >= 4
Truth table0%0/4
A and B and C
A= $self->code == 101B= $version->type eq "hybi"C= $version->revision >= 4
ABCresult
0XX0
10X0
1100
1111
186 {
187 0 ▶ return( $self->error( "key value is required." ) ) if( !defined( $self->key ) || !length( $self->key ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->key and length $self->key 0 0 0
Condition0%0/3
defined $self->key and length $self->key
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->key and length $self->key
defined $self->key length $self->key
Truth table0%0/3
A and B
A= defined $self->keyB= length $self->key
ABresult
0X0
100
111
188 0 my $key = $self->key;
189 # This fixed uuid value is provided for in the rfc6455
190 # See section 1,3 (opening handshake) <https://datatracker.ietf.org/doc/html/rfc6455#section-1.3>
191 # since version 4
192 0 $key .= GUID;
193 0 $key = Digest::SHA::sha1( $key );
194 0 $key = MIME::Base64::encode_base64( $key );
195 0 $key =~ s{\s+}{}g;
196 0 $h->header( 'Sec-WebSocket-Accept' => $key );
197 }
198 else
199 {
200 0 $h->remove_header( 'Sec-WebSocket-Accept' );
201 }
202
203 # <https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-04#section-5.2.2>
204 0 ▶ if( $self->code == 101 && $version->type eq 'hybi' && $version->revision >= 4 && $version->revision <= 5 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->code == 101 and $version->type eq 'hybi' and $version->revision >= 4 and $version->revision <= 5) { } 0 0 0
Condition0%0/9
$self->code == 101 and $version->type eq "hybi" and $version->revision >= 4 and $version->revision <= 5
!ll&&!rl&&r
000
$self->code == 101 and $version->type eq "hybi" and $version->revision >= 4
!ll&&!rl&&r
000
$self->code == 101 and $version->type eq "hybi"
!ll&&!rl&&r
000
MC/DC0%0/4
$self->code == 101 and $version->type eq "hybi" and $version->revision >= 4 and $version->revision <= 5
$self->code == 101 $version->type eq "hybi" $version->revision >= 4 $version->revision <= 5
Truth table0%0/5
A and B and C and D
A= $self->code == 101B= $version->type eq "hybi"C= $version->revision >= 4D= $version->revision <= 5
ABCDresult
0XXX0
10XX0
110X0
11100
11111
205 {
206 0 my $nonce = $self->__generate_16bit_nonce();
207 0 $h->header( 'Sec-WebSocket-Nonce' => $nonce );
208 }
209 else
210 {
211 0 $h->remove_header( 'Sec-WebSocket-Nonce' );
212 }
213
214 0 ▶ if( $self->subprotocol->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->subprotocol->length) 0 0 0
215 {
216 0 ▶ if( ( $version->type eq 'hixie' && $version->revision == 76 ) ||
Branch: 2 branches
BranchTrueFalseTotal
if ($version->type eq 'hixie' and $version->revision == 76 or $version->type eq 'hybi') { } 0 0 0
elsif ($version->type eq 'hixie' and $version->revision >= 10 and $version->revision <= 75) { } 0 0 0
Condition0%0/6
$version->type eq "hixie" and $version->revision == 76 or $version->type eq "hybi"
l!l&&r!l&&!r
000
$version->type eq "hixie" and $version->revision == 76
!ll&&!rl&&r
000
MC/DC0%0/3
$version->type eq "hixie" and $version->revision == 76 or $version->type eq "hybi"
$version->type eq "hixie" $version->revision == 76 $version->type eq "hybi"
Truth table0%0/5
A and B or C
A= $version->type eq "hixie"B= $version->revision == 76C= $version->type eq "hybi"
ABCresult
11X1
0X11
1011
0X00
1000
217 ( $version->type eq 'hybi' ) )
218 {
219 0 my $sep = ',';
220 # From draft hybi revision 3 and lower and all hixie drafts, the separator is a space.
221 # It changed with hybi draft revision 4
222 0 ▶ if( ( $version->type eq 'hixie' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($version->type eq "hixie" or $version->type eq "hybi" and $version->revision <= 3) 0 0 0
Condition0%0/6
$version->type eq "hixie" or $version->type eq "hybi" and $version->revision <= 3
l!l&&r!l&&!r
000
$version->type eq "hybi" and $version->revision <= 3
!ll&&!rl&&r
000
MC/DC0%0/3
$version->type eq "hixie" or $version->type eq "hybi" and $version->revision <= 3
$version->type eq "hixie" $version->type eq "hybi" $version->revision <= 3
Truth table0%0/4
A or B and C
A= $version->type eq "hixie"B= $version->type eq "hybi"C= $version->revision <= 3
ABCresult
1XX1
0111
00X0
0100
223 ( $version->type eq 'hybi' && $version->revision <= 3 ) )
224 {
225 0 $sep = ' ';
226 }
227 0 $h->header( 'Sec-WebSocket-Protocol' => $self->subprotocol->join( $sep )->scalar )
228 }
229 ▶ elsif( $version->type eq 'hixie' && $version->revision >= 10 && $version->revision <= 75 )
Condition0%0/6
$version->type eq "hixie" and $version->revision >= 10 and $version->revision <= 75
!ll&&!rl&&r
000
$version->type eq "hixie" and $version->revision >= 10
!ll&&!rl&&r
000
MC/DC0%0/3
$version->type eq "hixie" and $version->revision >= 10 and $version->revision <= 75
$version->type eq "hixie" $version->revision >= 10 $version->revision <= 75
Truth table0%0/4
A and B and C
A= $version->type eq "hixie"B= $version->revision >= 10C= $version->revision <= 75
ABCresult
0XX0
10X0
1100
1111
230 {
231 0 $h->header( 'WebSocket-Protocol' => $self->subprotocol->join( ' ' )->scalar )
232 }
233 else
234 {
235 0 $h->remove_header( qw( Sec-WebSocket-Protocol WebSocket-Protocol ) );
236 }
237 }
238
239 0 ▶ if( $self->extensions->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->extensions->length) 0 0 0
240 {
241 # if( $self->
242 # This will automatically stringify each object in the array to their proper header representation
243 0 $h->header( 'Sec-WebSocket-Extensions' => $self->extensions->join( ',' )->scalar );
244 }
245
246 0 ▶ if( $self->cookies->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cookies->length) 0 0 0
247 {
248 # $h->header( 'Set-Cookie' => $self->cookies->join( ',' )->scalar );
249 $self->cookies->for(sub
250 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
251 0 $h->header( 'Set-Cookie' => $_ );
252 0 });
253 }
254 0 return( $h->as_string( $eol ) );
255 }
256  
257 0 ▶sub key { return( shift->_set_get_scalar_as_object( 'key', @_ ) ); }
Subroutine key: not called CC=1 SCAR=6.9
Pod documented
258  
259 0 ▶sub key1 { return( shift->_set_get_scalar_as_object( 'key1', @_ ) ); }
Subroutine key1: not called CC=1 SCAR=6.9
Pod documented
260  
261 0 ▶sub key2 { return( shift->_set_get_scalar_as_object( 'key2', @_ ) ); }
Subroutine key2: not called CC=1 SCAR=6.9
Pod documented
262  
263 0 ▶sub location { return( shift->headers->header( 'Location', @_ ) ); }
Subroutine location: not called CC=1 SCAR=6.9
Pod documented
264  
265 0 ▶sub number1 { return( shift->_number( 'number1', 'key1', @_ ) ); }
Subroutine number1: not called CC=1 SCAR=6.9
Pod documented
266  
267 0 ▶sub number2 { return( shift->_number( 'number2', 'key2', @_ ) ); }
Subroutine number2: not called CC=1 SCAR=6.9
Pod documented
268  
269 0 ▶sub origin { return( shift->headers->header( 'Sec-WebSocket-Origin', @_ ) ); }
Subroutine origin: not called CC=1 SCAR=6.9
Pod documented
270  
271 sub parse
272 4 ▶{
Subroutine parse: called CC=96 SCAR=81.5
Pod documented
273 4 my $self = shift( @_ );
274 # Get the HTTP::Request object from parsing
275 4 my $resp;
276 0 ▶ try
Subroutine __ANON__: called CC=2 SCAR=7.4
Subroutine __ANON__: called CC=22 SCAR=48.6
Branch: 3 branches
BranchTrueFalseTotal
unless defined $Nice::Try::NEED_TO_RETURN 4 0 4
if ($INC{"threads.pm"} and not exists $INC{"forks.pm"}) 0 4 4
wantarray ? : 0 1 1
Condition33%1/3
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
!ll&&!rl&&r
400
MC/DC0%0/2
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
$INC{"threads.pm"} not exists $INC{"forks.pm"}
Truth table33%1/3
A and not(B)
A= $INC{"threads.pm"}B= not exists $INC{"forks.pm"}
ABresult
0X0
100
111
277 4 {
278 4 ▶ return(1) unless( defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 4 4
279 # Add data to buffer
280 4 ▶ $self->_append( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_append(@_) or return &$Nice::Try::RETURN($self->pass_error) 3 1 4
281 # my $rv = $self->_append( @_ );
282 # return( $self->pass_error ) if( !defined( $rv ) );
283 3 ▶ unless( $self->buffer->match( qr{^HTTP/1\.1[[:blank:]\h]+101 } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->buffer->match(qr"^HTTP/1\.1[[:blank:]\h]+101 ")) 2 1 3
284 {
285 2 ▶ my $bad_line = ( $self->buffer->length > 80 ? $self->buffer->substr( 0, 77 )->append( '...' ) : $self->buffer );
Branch: 1 branch
BranchTrueFalseTotal
$self->buffer->length > 80 ? : 1 1 2
286 2 $bad_line->replace( qr/(\x0d?\x0a)+$/s, '' );
287 2 return( $self->error( "Wrong response line. Got \"$bad_line\", but expected something starting with \"HTTP/1.1 101 \"" ) );
288 }
289 1 ▶ $resp = HTTP::Response->parse( $self->buffer->scalar ) || return( $self->pass_error );
Condition50%1/2
'HTTP::Response'->parse($self->buffer->scalar) || (return &$Nice::Try::RETURN($self->pass_error))
l!l
10
MC/DC0%0/1
'HTTP::Response'->parse($self->buffer->scalar) || (return &$Nice::Try::RETURN($self->pass_error))
'HTTP::Response'->parse($self->buffer->scalar)
Truth table50%1/2
A
A= 'HTTP::Response'->parse($self->buffer->scalar)
Aresult
11
00
290 1 $self->headers( $resp->headers );
291 1 $self->protocol( $resp->protocol );
292 1 $self->code( $resp->code );
293 1 $self->status( $resp->message );
294 # The rest is the body
295 1 $self->buffer( $resp->content );
296 }
297 0 ▶ catch( $e )
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine __ANON__: not called CC=1 SCAR=3.4
Subroutine __ANON__: not called CC=1 SCAR=3.4
Subroutine __ANON__: not called CC=3 SCAR=19.9
Branch: 34 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 4 4
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::TRY ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 4 4
elsif (defined $Nice::Try::WANTARRAY) { } 4 0 4
if defined $Nice::Try::LAST_VAL 0 0 0
length $@ ? : 0 4 4
unless builtin::blessed($@) 4 0 4
if ($Nice::Try::DIED) 0 4 4
if ($Nice::Try::HAS_CATCH) 0 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 1 1
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 1 1
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 1 1
elsif (defined $Nice::Try::WANTARRAY) { } 1 0 1
Condition37%3/8
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
400
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
10
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
100
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
Truth table33%1/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table50%1/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
Truth table33%1/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
298 0 {
299 0 return( $self->error( "Error parsing response data: $e" ) );
300 0 ▶ }
Subroutine BEGIN: called CC=1 SCAR=4.3
Subroutine BEGIN: called CC=1 SCAR=4.3
Subroutine BEGIN: called CC=1 SCAR=4.3
Branch: 56 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::CATCH ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
if $@ 0 0 0
if (defined $Nice::Try::CATCH_DIED) 0 4 4
if (defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq 'return' and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa('Nice::Try::SENTINEL')) { } 3 1 4
elsif (scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa('Nice::Try::SENTINEL')) { } 0 1 1
if defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return" 2 1 3
if (not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return") 3 0 3
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 3 3
if ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
if (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__NEXT__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__LAST__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__REDO__') { } 0 0 0
elsif (defined $Nice::Try::BREAK and $Nice::Try::BREAK eq 'return') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 3 0 3
$Nice::Try::WANTARRAY ? : 0 3 3
$Nice::Try::WANTARRAY ? : 0 0 0
scalar @Nice::Try::VOID > 1 ? : 0 0 0
if (defined $Nice::Try::BREAK) 0 1 1
if ($Nice::Try::BREAK eq 'next') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'last') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'redo') { } 0 0 0
scalar @Nice::Try::LAST_VAL > 1 ? : 0 1 1
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
Condition28%14/50
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
013
defined $Nice::Try::WANTARRAY or defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
400
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
not builtin::blessed($Nice::Try::RETVAL[0]) or builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
301
builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
010
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
102
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
120
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
300
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
!ll&&!rl&&r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
010
not builtin::blessed($Nice::Try::VOID[0]) or builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
001
builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
010
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
00
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC16%1/6
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
defined $Nice::Try::WANTARRAY defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return" not builtin::blessed($Nice::Try::RETVAL[0]) builtin::blessed($Nice::Try::RETVAL[0]) not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/2
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
not defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return"
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__NEXT__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__LAST__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__REDO__"
MC/DC0%0/4
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
scalar @Nice::Try::VOID not builtin::blessed($Nice::Try::VOID[0]) builtin::blessed($Nice::Try::VOID[0]) not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table20%2/10
A or B and C and not(D) or E and not(F)
A= defined $Nice::Try::WANTARRAYB= defined $Nice::Try::BREAKC= $Nice::Try::BREAK eq "return"D= not builtin::blessed($Nice::Try::RETVAL[0])E= builtin::blessed($Nice::Try::RETVAL[0])F= not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
ABCDEFresult
00XXXX0
010XXX0
1XX00X0
1XX0100
01100X0
0110100
1XX1XX1
1XX0111
0111XX1
0110111
Truth table66%2/3
not(A) or B
A= not defined $Nice::Try::BREAKB= $Nice::Try::BREAK eq "return"
ABresult
1X1
011
000
Truth table33%1/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__NEXT__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__LAST__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__REDO__"
ABresult
0X0
100
111
Truth table20%1/5
A and not(B) or C and not(D)
A= scalar @Nice::Try::VOIDB= not builtin::blessed($Nice::Try::VOID[0])C= builtin::blessed($Nice::Try::VOID[0])D= not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table0%0/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
301 # Used in both parse() and parse_chunk()
302 1 return( $self->parse_body );
303 }
304  
305 sub parse_body
306 1 ▶{
Subroutine parse_body: called CC=17 SCAR=49.3
Pod documented
307 1 my $self = shift( @_ );
308 # Process body
309 1 my $h = $self->headers;
310 # Check if there is a Sec-WebSocket-Version header (available since draft revision 4)
311 1 ▶ if( $h->header( 'Sec-WebSocket-Version' ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($h->header('Sec-WebSocket-Version')) { } 1 0 1
elsif ($h->header('Sec-WebSocket-Accept')) { } 0 0 0
elsif ($h->header('Sec-WebSocket-Origin')) { } 0 0 0
312 {
313 1 $self->version( $h->header( 'Sec-WebSocket-Version' )->scalar );
314 }
315 elsif( $h->header( 'Sec-WebSocket-Accept' ) )
316 {
317 # $self->version( 'draft-ietf-hybi-10' );
318 # The latest version, i.e. revision 17
319 0 $self->version( 'draft-ietf-hybi-17' );
320 }
321 elsif( $h->header( 'Sec-WebSocket-Origin' ) )
322 {
323 # $self->version( 'draft-ietf-hybi-00' );
324 # The last version that used the response header Sec-WebSocket-Origin
325 0 $self->version( 'draft-ietf-hybi-03' );
326 0 ▶ return(1) if( $self->buffer->length < 16 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->buffer->length < 16 0 0 0
327 0 my $checksum = $self->buffer->substr( 0, 16, '' );
328 0 $self->checksum( $checksum );
329 }
330 else
331 {
332 0 $self->version( 'draft-hixie-75' );
333 }
334 1 $self->is_done(1);
335
336 # Finalise
337 1 my $v = $self->version;
338 # if( $self->version eq 'draft-hixie-75' )
339 1 ▶ if( $v->type eq 'hixie' && $v->revision == 75 )
Branch: 2 branches
BranchTrueFalseTotal
if ($v->type eq 'hixie' and $v->revision == 75) { } 0 1 1
elsif ($v->type eq 'hixie' and $v->revision == 76 or $v->type eq 'hybi' and $v->revision <= 3) { } 0 1 1
Condition33%1/3
$v->type eq "hixie" and $v->revision == 75
!ll&&!rl&&r
100
MC/DC0%0/2
$v->type eq "hixie" and $v->revision == 75
$v->type eq "hixie" $v->revision == 75
Truth table33%1/3
A and B
A= $v->type eq "hixie"B= $v->revision == 75
ABresult
0X0
100
111
340 {
341 0 my $location = $h->header( 'WebSocket-Location' );
342 0 ▶ return( $self->error( "No \"WebSocket-Location\" header found." ) ) unless( $location->defined );
Branch: 1 branch
BranchTrueFalseTotal
unless $location->defined 0 0 0
343 0 $self->location( $location );
344 0 my $uri = URI->new( $location );
345 0 ▶ $self->secure(1) if( $uri->scheme eq 'wss' );
Branch: 1 branch
BranchTrueFalseTotal
if $uri->scheme eq "wss" 0 0 0
346 0 $self->host( $uri->host );
347 0 $self->uri( $uri );
348 0 $self->origin( $h->header( 'WebSocket-Origin' ) );
349 0 $self->subprotocol( $h->header( 'WebSocket-Protocol' )->split( qr/[[:blank:]\h]+/ ) );
350 }
351 # elsif( $self->version eq 'draft-ietf-hybi-00' )
352 ▶ elsif( ( $v->type eq 'hixie' && $v->revision == 76 ) ||
Condition33%3/9
$v->type eq "hixie" and $v->revision == 76 or $v->type eq "hybi" and $v->revision <= 3
l!l&&r!l&&!r
001
$v->type eq "hixie" and $v->revision == 76
!ll&&!rl&&r
100
$v->type eq "hybi" and $v->revision <= 3
!ll&&!rl&&r
010
MC/DC0%0/4
$v->type eq "hixie" and $v->revision == 76 or $v->type eq "hybi" and $v->revision <= 3
$v->type eq "hixie" $v->revision == 76 $v->type eq "hybi" $v->revision <= 3
Truth table14%1/7
A and B or C and D
A= $v->type eq "hixie"B= $v->revision == 76C= $v->type eq "hybi"D= $v->revision <= 3
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
353 ( $v->type eq 'hybi' && $v->revision <= 3 ) )
354 {
355 0 my $location = $h->header( 'Sec-WebSocket-Location' );
356 0 ▶ return( $self->error( "No \"Sec-WebSocket-Location\" header found." ) ) unless( $location->defined );
Branch: 1 branch
BranchTrueFalseTotal
unless $location->defined 0 0 0
357 0 $self->location( $location );
358 0 my $uri = URI->new( $location );
359 0 ▶ $self->secure(1) if( $uri->scheme eq 'wss' );
Branch: 1 branch
BranchTrueFalseTotal
if $uri->scheme eq "wss" 0 0 0
360 0 $self->host( $uri->host );
361 0 $self->uri( $uri );
362 0 $self->origin( $h->header( 'Sec-WebSocket-Origin' ) );
363 0 $self->subprotocol( $h->header( 'Sec-WebSocket-Protocol' )->split( qr/[[:blank:]\h]+/ ) );
364 }
365 # No more Sec-WebSocket-Location or Sec-WebSocket-Origin on and after draft revision 4
366 else
367 {
368 1 $self->subprotocol( $h->header( 'Sec-WebSocket-Protocol' )->split( qr/[[:blank:]\h]*\,[[:blank:]\h]*/ ) );
369 }
370
371 1 ▶ if( $h->header( 'Sec-WebSocket-Extensions' )->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($h->header("Sec-WebSocket-Extensions")->length) 0 1 1
372 {
373 # Returns a Module::Generic::Array of WebSocket::Extension objects
374 0 ▶ my $ref = WebSocket::Extension->new_from_multi( $h->header( 'Sec-WebSocket-Extensions' )->scalar ) ||
Condition0%0/2
'WebSocket::Extension'->new_from_multi($h->header('Sec-WebSocket-Extensions')->scalar) || (return $self->pass_error('WebSocket::Extension'->error))
l!l
00
MC/DC0%0/1
'WebSocket::Extension'->new_from_multi($h->header('Sec-WebSocket-Extensions')->scalar) || (return $self->pass_error('WebSocket::Extension'->error))
'WebSocket::Extension'->new_from_multi($h->header('Sec-WebSocket-Extensions')->scalar)
Truth table0%0/2
A
A= 'WebSocket::Extension'->new_from_multi($h->header('Sec-WebSocket-Extensions')->scalar)
Aresult
11
00
375 return( $self->pass_error( WebSocket::Extension->error ) );
376 0 $self->extensions( $ref );
377 }
378 1 return( $self );
379 }
380  
381 1 ▶sub status { return( shift->_set_get_scalar_as_object( 'status', @_ ) ); }
Subroutine status: called CC=1 SCAR=0.0
Pod documented
382  
383 # Server response version header can contain one or more versions
384 sub version
385 12 ▶{
Subroutine version: called CC=7 SCAR=20.2
Pod documented
386 12 my $self = shift( @_ );
387 # When setting value, we use an array object of WebSocket::Version objects
388 12 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 6 12
389 {
390 6 my $v = shift( @_ );
391 6 ▶ if( !ref( $v ) || ( $self->_is_object( $v ) && overload::Method( $v, '""' ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $v or $self->_is_object($v) and overload::Method($v, "\"\"")) 6 0 6
Condition50%3/6
not ref $v or $self->_is_object($v) and overload::Method($v, "\"\"")
l!l&&r!l&&!r
150
$self->_is_object($v) and overload::Method($v, "\"\"")
!ll&&!rl&&r
005
MC/DC0%0/3
not ref $v or $self->_is_object($v) and overload::Method($v, "\"\"")
not ref $v $self->_is_object($v) overload::Method($v, "\"\"")
Truth table50%2/4
not(A) or B and C
A= not ref $vB= $self->_is_object($v)C= overload::Method($v, "\"\"")
ABCresult
1XX1
0111
00X0
0100
392 {
393 6 $v = [split( /[[:blank:]\h]*\,[[:blank:]\h]*/, "$v" )];
394 }
395 6 my $ref = [];
396 6 foreach my $s ( @$v )
397 {
398 6 ▶ my $vers = WebSocket::Version->new( $s ) ||
Condition50%1/2
'WebSocket::Version'->new($s) || (return 'WebSocket::Version'->error)
l!l
60
MC/DC0%0/1
'WebSocket::Version'->new($s) || (return 'WebSocket::Version'->error)
'WebSocket::Version'->new($s)
Truth table50%1/2
A
A= 'WebSocket::Version'->new($s)
Aresult
11
00
399 return( WebSocket::Version->error );
400 6 push( @$ref, $vers );
401 }
402 6 $self->_set_get_object_array_object( 'version', 'WebSocket::Version', $ref );
403 }
404 12 return( $self->_set_get_object_array_object( 'version', 'WebSocket::Version' )->first );
405 }
406  
407 0 ▶sub versions { return( shift->_set_get_object_array_object( 'version', 'WebSocket::Version', @_ ) ); }
Subroutine versions: not called CC=1 SCAR=6.9
Pod documented
408  
409 sub _number
410 0 ▶{
Subroutine _number: not called CC=3 SCAR=24.8
411 0 my $self = shift( @_ );
412 0 my( $name, $key, $value ) = @_;
413 0 my $method = "SUPER::$name";
414 0 ▶ return( $self->$method( $value ) ) if( length( "$value" ) );
Branch: 1 branch
BranchTrueFalseTotal
if length "$value" 0 0 0
415 0 $value = $self->$method();
416 0 ▶ $value = $self->_extract_number( $self->$key ) if( !length( "$value" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length "$value" 0 0 0
417 0 return( $value );
418 }
419  
420 # Called from parse_chunk()
421 sub _parse_body_chunk
422 0 ▶{
Subroutine _parse_body_chunk: not called CC=1 SCAR=6.9
423 0 my $self = shift( @_ );
424 0 my $resp = $self->SUPER::_parse_body_chunk;
425 0 $self->protocol( $resp->protocol );
426 0 $self->code( $resp->code );
427 0 $self->headers( $resp->headers );
428 # The rest is the body
429 0 $self->buffer( $resp->content );
430 # Used in both parse() and parse_chunk()
431 0 return( $self->parse_body );
432 }
433  
434 5 1;
435 # NOTE: POD
436 __END__
« WebSocket/Headers.pm ↑ Summary WebSocket/Request.pm »