WebSocket/Headers.pm

filter: Statementstmt 48.2% 97 / 201 Branchbran 15.5% 33 / 212 Conditioncond 22.8% 16 / 70 MC/DCmcdc 5.5% 2 / 36 Subroutinesub 78.2% 18 / 23 Podpod 100% 2 / 2 totaltotal 30.8% 168 / 544 CC 131 SCAR 80.2
CC
131
Cov
30%
header
4521.5
__ANON__
190.3
__ANON__
13.3
CRAP 3043.7
« WebSocket/Server.pm ↑ Summary WebSocket/Response.pm »
1 ##----------------------------------------------------------------------------
2 ## WebSocket Client & Server - ~/lib/WebSocket/Headers.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/09/20
7 ## Modified 2021/09/20
8 ## You can use, copy, modify and redistribute this package and associated
9 ## files under the same terms as Perl itself.
10 ##----------------------------------------------------------------------------
11 package WebSocket::Headers;
12 BEGIN
13 6 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶ use parent qw( HTTP::Headers Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use Nice::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use Want;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 our $VERSION = 'v0.1.0';
21 };
22  
23 sub exists
24 0 ▶{
Subroutine exists: not called CC=3 SCAR=24.8
Pod documented
25 0 my $self = shift( @_ );
26 0 my $name = shift( @_ );
27 0 ▶ return(0) if( !defined( $name ) || !length( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
28 0 return( CORE::exists( $self->{ $name } ) );
29 }
30  
31 sub header
32 137 ▶{
Subroutine header: called CC=102 SCAR=84.2
Pod documented
33 137 my $self = shift( @_ );
34 137 my @args = @_;
35 # Set mode
36 137 ▶ if( scalar( @args ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 1) 27 110 137
37 {
38 27 ▶ for( my $i = 0; $i < scalar( @args ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 60 27 87
39 {
40 # if( $args[$i] eq 'debug' )
41 # {
42 # my $trace = $self->_get_stack_trace;
43 # print( STDERR ref( $self ), "::header: called with 'debug' header -> $trace\n" );
44 # }
45 60 my $v = $args[$i + 1];
46 60 ▶ if( $self->_is_array( $v ) && $self->_is_object( $v ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($v) and $self->_is_object($v)) { } 0 60 60
elsif (overload::Overloaded($v) and overload::Method($v, '""')) { } 2 114 116
Condition33%1/3
$self->_is_array($v) and $self->_is_object($v)
!ll&&!rl&&r
6000
MC/DC0%0/2
$self->_is_array($v) and $self->_is_object($v)
$self->_is_array($v) $self->_is_object($v)
Truth table33%1/3
A and B
A= $self->_is_array($v)B= $self->_is_object($v)
ABresult
0X0
100
111
47 {
48 0 $args[$i + 1] = [@$v];
49 }
50 ▶ elsif( overload::Overloaded( $v ) && overload::Method( $v, '""' ) )
Condition100%3/3
overload::Overloaded($v) and overload::Method($v, "\"\"")
!ll&&!rl&&r
5622
MC/DC100%2/2
overload::Overloaded($v) and overload::Method($v, "\"\"")
overload::Overloaded($v) overload::Method($v, "\"\"")
Truth table100%3/3
A and B
A= overload::Overloaded($v)B= overload::Method($v, "\"\"")
ABresult
0X0
100
111
51 {
52 2 $args[$i + 1] = "$v";
53 }
54 }
55 }
56
57 0 ▶ try
Subroutine __ANON__: not called CC=2 SCAR=8.0
Subroutine __ANON__: called CC=23 SCAR=52.5
Branch: 3 branches
BranchTrueFalseTotal
unless defined $Nice::Try::NEED_TO_RETURN 124 13 137
if ($INC{"threads.pm"} and not exists $INC{"forks.pm"}) 0 137 137
wantarray ? : 0 0 0
Condition33%1/3
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
!ll&&!rl&&r
13700
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
58 137 {
59 137 my @rv = $self->SUPER::header( @args );
60 # Convert
61 137 ▶ for( my $i = 0; $i < scalar( @rv ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @rv) 38 137 175
62 {
63 38 ▶ if( !ref( $rv[$i] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $rv[$i]) { } 38 0 38
elsif (ref $rv[$i] eq 'ARRAY') { } 0 0 0
64 {
65 38 $rv[$i] = $self->new_scalar( $rv[$i] );
66 }
67 elsif( ref( $rv[$i] ) eq 'ARRAY' )
68 {
69 0 $rv[$i] = $self->new_array( $rv[$i] );
70 }
71 }
72 137 ▶ if( !scalar( @rv ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @rv) 99 38 137
73 {
74 99 @rv = ( $self->new_scalar( undef ) );
75 }
76 137 ▶ return( @rv ) if( wantarray() );
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 137 137
77 137 ▶ return( $rv[0] ) if( @rv <= 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @rv <= 1 137 0 137
78 0 return( join( ", ", @rv ) );
79 }
80 0 ▶ catch( $e )
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine __ANON__: not called CC=1 SCAR=4.0
Subroutine __ANON__: not called CC=1 SCAR=4.0
Subroutine __ANON__: not called CC=4 SCAR=25.9
Branch: 34 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 137 137
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 137 137
elsif (defined $Nice::Try::WANTARRAY) { } 118 19 137
if defined $Nice::Try::LAST_VAL 0 19 19
length $@ ? : 0 137 137
unless builtin::blessed($@) 137 0 137
if ($Nice::Try::DIED) 0 137 137
if ($Nice::Try::HAS_CATCH) 0 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
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
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
Condition12%1/8
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
13700
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
00
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
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 table0%0/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
81 0 {
82 0 ▶ return( $self->error( "Error ", ( scalar( @args ) > 1 ? 'setting' : 'getting' ), " header value(s): $e" ) );
Branch: 1 branch
BranchTrueFalseTotal
scalar @args > 1 ? : 0 0 0
83 0 ▶ }
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine BEGIN: called CC=1 SCAR=4.9
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 137 137
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')) { } 137 0 137
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 0 0
if defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return" 137 0 137
if (not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return") 137 0 137
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 137 137
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 ? : 137 0 137
$Nice::Try::WANTARRAY ? : 0 137 137
$Nice::Try::WANTARRAY ? : 0 0 0
scalar @Nice::Try::VOID > 1 ? : 0 0 0
if (defined $Nice::Try::BREAK) 0 0 0
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 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
Condition20%10/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
00137
defined $Nice::Try::WANTARRAY or defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
118190
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
0019
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
191180
builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
00118
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
00137
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
01370
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
13700
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
000
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
000
builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
000
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/DC0%0/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 table33%1/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 table0%0/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
84 }
85  
86 6 1;
87 # NOTE: POD
88 __END__
« WebSocket/Server.pm ↑ Summary WebSocket/Response.pm »