blib/lib/Unblock/WebSocket/_UTF8.pm

filter: Statementstmt 100% 34 / 34 Branchbran 80.0% 16 / 20 Conditioncond 50.0% 6 / 12 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 77.3% 65 / 84 CC 16 SCAR 15.2
CC
16
Cov
85%
decode
6.4
_valid_codepoints
5.0
valid_bytes
4.2
CRAP 4.6
« blib/lib/Unblock/WebSocket/_Random.pm ↑ Summary vendor/bq_websocket/bq_websocket.c »
1 package Unblock::WebSocket::_UTF8;
2  
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 107 ▶sub _valid_codepoints {
Subroutine _valid_codepoints: called CC=5 SCAR=16.1
8 107 my ($text) = @_;
9 107 for my $char (split //, $text) {
10 6759 my $cp = ord($char);
11 6759 ▶ return 0 if $cp > 0x10ffff;
Branch: 1 branch
BranchTrueFalseTotal
if $cp > 1114111 3 6756 6759
12 6756 ▶ return 0 if $cp >= 0xd800 && $cp <= 0xdfff;
Branch: 1 branch
BranchTrueFalseTotal
if $cp >= 55296 and $cp <= 57343 4 6752 6756
Condition100%3/3
$cp >= 55296 and $cp <= 57343
!ll&&!rl&&r
6740124
MC/DC100%2/2
$cp >= 55296 and $cp <= 57343
$cp >= 55296 $cp <= 57343
Truth table100%3/3
A and B
A= $cp >= 55296B= $cp <= 57343
ABresult
0X0
100
111
13 }
14 100 return 1;
15 }
16  
17 113 ▶sub decode {
Subroutine decode: called CC=6 SCAR=18.6
Pod undocumented
18 113 my ($class, $bytes) = @_;
19 113 ▶ croak 'decode(): bytes must be a defined scalar'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $bytes or ref $bytes 0 113 113
Condition33%1/3
not defined $bytes or ref $bytes
l!l&&r!l&&!r
00113
MC/DC0%0/2
not defined $bytes or ref $bytes
not defined $bytes ref $bytes
Truth table33%1/3
not(A) or B
A= not defined $bytesB= ref $bytes
ABresult
1X1
011
000
20 if !defined($bytes) || ref($bytes);
21  
22 113 my $text = "$bytes";
23 113 ▶ croak 'decode(): bytes must be a byte string'
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($text, 1) 0 113 113
24 unless utf8::downgrade($text, 1);
25 113 ▶ croak 'decode(): invalid UTF-8'
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::decode($text) 19 94 113
26 unless utf8::decode($text);
27 94 ▶ croak 'decode(): invalid Unicode scalar value'
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_codepoints($text) 4 90 94
28 unless _valid_codepoints($text);
29  
30 90 return $text;
31 }
32  
33 13 ▶sub encode {
Subroutine encode: called CC=4 SCAR=14.3
Pod undocumented
34 13 my ($class, $text) = @_;
35 13 ▶ croak 'encode(): text must be a defined scalar'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $text or ref $text 0 13 13
Condition33%1/3
not defined $text or ref $text
l!l&&r!l&&!r
0013
MC/DC0%0/2
not defined $text or ref $text
not defined $text ref $text
Truth table33%1/3
not(A) or B
A= not defined $textB= ref $text
ABresult
1X1
011
000
36 if !defined($text) || ref($text);
37  
38 13 my $copy = "$text";
39 13 ▶ croak 'encode(): invalid Unicode scalar value'
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_codepoints($copy) 3 10 13
40 unless _valid_codepoints($copy);
41  
42 10 utf8::encode($copy);
43 10 return $copy;
44 }
45  
46 58 ▶sub valid_bytes {
Subroutine valid_bytes: called CC=4 SCAR=14.5
Pod undocumented
47 58 my ($class, $bytes) = @_;
48 58 ▶ return 0 if !defined($bytes) || ref($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $bytes or ref $bytes 0 58 58
Condition33%1/3
not defined $bytes or ref $bytes
l!l&&r!l&&!r
0058
MC/DC0%0/2
not defined $bytes or ref $bytes
not defined $bytes ref $bytes
Truth table33%1/3
not(A) or B
A= not defined $bytesB= ref $bytes
ABresult
1X1
011
000
49 58 ▶ return eval { $class->decode($bytes); 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $class->decode($bytes); 1 } } ? : 48 10 58
50 }
51  
52 14 1;
« blib/lib/Unblock/WebSocket/_Random.pm ↑ Summary vendor/bq_websocket/bq_websocket.c »