| 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
| |||||||||||||||||||||||||||||
| 12 | 6756 | ▶ | return 0 if $cp >= 0xd800 && $cp <= 0xdfff; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$cp >= 55296 and $cp <= 57343
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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
not defined $bytes or ref $bytes
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 24 | unless utf8::downgrade($text, 1); | ||||||||||||||||||||||||||||
| 25 | 113 | ▶ | croak 'decode(): invalid UTF-8' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | unless utf8::decode($text); | ||||||||||||||||||||||||||||
| 27 | 94 | ▶ | croak 'decode(): invalid Unicode scalar value' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
not defined $text or ref $text
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
| |||||||||||||||||||||||||||||
| 36 | if !defined($text) || ref($text); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 13 | my $copy = "$text"; | |||||||||||||||||||||||||||
| 39 | 13 | ▶ | croak 'encode(): invalid Unicode scalar value' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
not defined $bytes or ref $bytes
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
| |||||||||||||||||||||||||||||
| 49 | 58 | ▶ | return eval { $class->decode($bytes); 1 } ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 14 | 1; | |||||||||||||||||||||||||||