blib/lib/Linux/Event/WebSocket/_Random.pm

filter: Statementstmt 80.9% 34 / 42 Branchbran 42.3% 11 / 26 Conditioncond 22.2% 4 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 2 totaltotal 53.2% 57 / 107 CC 20 SCAR 28.3
CC
20
Cov
57%
mask_key
40.4
bytes
15.8
_random_fh
5.2
CRAP 16.9
« blib/lib/Linux/Event/WebSocket/_Frame.pm ↑ Summary blib/lib/Linux/Event/WebSocket/_Engine.pm »
1 package Linux::Event::WebSocket::_Random;
2 11 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Fcntl qw(FD_CLOEXEC F_GETFD F_SETFD O_RDONLY);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 my $RANDOM_FH;
10  
11 8 ▶sub _random_fh () {
Subroutine _random_fh: called CC=5 SCAR=16.6
12 8 ▶ return $RANDOM_FH if $RANDOM_FH;
Branch: 1 branch
BranchTrueFalseTotal
if $RANDOM_FH 2 6 8
13  
14 6 ▶ sysopen($RANDOM_FH, '/dev/urandom', O_RDONLY)
Branch: 1 branch
BranchTrueFalseTotal
sysopen $RANDOM_FH, "/dev/urandom", 0 or die "open /dev/urandom: $!" 6 0 6
15 or die "open /dev/urandom: $!";
16  
17 6 my $flags = fcntl($RANDOM_FH, F_GETFD, 0);
18 6 ▶ die "fcntl(F_GETFD) /dev/urandom: $!" if !defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 0 6 6
19 6 ▶ fcntl($RANDOM_FH, F_SETFD, $flags | FD_CLOEXEC)
Branch: 1 branch
BranchTrueFalseTotal
fcntl $RANDOM_FH, 2, $flags | 1 or die "fcntl(F_SETFD) /dev/urandom: $!" 6 0 6
20 or die "fcntl(F_SETFD) /dev/urandom: $!";
21  
22 6 return $RANDOM_FH;
23 }
24  
25 0 ▶sub mask_key ($class) {
Subroutine mask_key: not called CC=7 SCAR=37.0
Pod undocumented
26 0 ▶ my $fh = $RANDOM_FH // _random_fh();
Condition0%0/3
$RANDOM_FH // _random_fh()
l!l&&r!l&&!r
000
MC/DC0%0/2
$RANDOM_FH // _random_fh()
$RANDOM_FH _random_fh()
Truth table0%0/3
A // B
A= $RANDOM_FHB= _random_fh()
ABresult
1X1
011
000
27 0 my $bytes = '';
28 0 ▶ while (length($bytes) < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $bytes < 4) 0 0 0
29 0 my $read = sysread($fh, $bytes, 4 - length($bytes), length($bytes));
30 0 ▶ next if !defined($read) && $!{EINTR};
Subroutine BEGIN: called CC=1 SCAR=2.6
Branch: 1 branch
BranchTrueFalseTotal
if not defined $read and $!{"EINTR"} 0 0 0
Condition0%0/3
not defined $read and $!{"EINTR"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $read and $!{"EINTR"}
not defined $read $!{"EINTR"}
Truth table0%0/3
not(A) and B
A= not defined $readB= $!{"EINTR"}
ABresult
0X0
100
111
31 0 ▶ die "read /dev/urandom: $!" if !defined $read;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read 0 0 0
32 0 ▶ die "read /dev/urandom: unexpected EOF" if $read == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $read == 0 0 0 0
33 }
34 0 return $bytes;
35 }
36  
37 8 ▶sub bytes ($class, $length) {
Subroutine bytes: called CC=10 SCAR=27.6
Pod undocumented
38 8 ▶ croak 'bytes(): length must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $length or ref $length or not "$length" =~ /\A[0-9]+\z/u or $length < 1 0 8 8
Condition33%3/9
not defined $length or ref $length or not "$length" =~ /\A[0-9]+\z/u or $length < 1
l!l&&r!l&&!r
008
not defined $length or ref $length or not "$length" =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
008
not defined $length or ref $length
l!l&&r!l&&!r
008
MC/DC0%0/4
not defined $length or ref $length or not "$length" =~ /\A[0-9]+\z/u or $length < 1
not defined $length ref $length not "$length" =~ /\A[0-9]+\z/u $length < 1
Truth table20%1/5
not(A) or B or not(C) or D
A= not defined $lengthB= ref $lengthC= not "$length" =~ /\A[0-9]+\z/uD= $length < 1
ABCDresult
1XXX1
01XX1
001X1
00011
00000
39 if !defined($length) || ref($length)
40 || "$length" !~ /\A[0-9]+\z/ || $length < 1;
41  
42 8 my $fh = _random_fh();
43 8 my $bytes = '';
44 8 ▶ while (length($bytes) < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $bytes < $length) 8 8 16
45 8 my $read = sysread($fh, $bytes, $length - length($bytes), length($bytes));
46 8 ▶ next if !defined($read) && $!{EINTR};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $read and $!{"EINTR"} 0 8 8
Condition33%1/3
not defined $read and $!{"EINTR"}
!ll&&!rl&&r
800
MC/DC0%0/2
not defined $read and $!{"EINTR"}
not defined $read $!{"EINTR"}
Truth table33%1/3
not(A) and B
A= not defined $readB= $!{"EINTR"}
ABresult
0X0
100
111
47 8 ▶ die "read /dev/urandom: $!" if !defined $read;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read 0 8 8
48 8 ▶ die "read /dev/urandom: unexpected EOF" if $read == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $read == 0 0 8 8
49 }
50  
51 8 return $bytes;
52 }
53  
54 11 1;
« blib/lib/Linux/Event/WebSocket/_Frame.pm ↑ Summary blib/lib/Linux/Event/WebSocket/_Engine.pm »