blib/lib/Sys/GetRandom.pm

filter: Statementstmt 100% 26 / 26 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 82.9% 39 / 47 CC 6 SCAR 14.3
CC
6
Cov
84%
random_bytes
7.3
BEGIN
1.0
BEGIN
1.0
CRAP 4.2
↑ Summary GetRandom.xs »
1 package Sys::GetRandom;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 our $VERSION = '0.03';
11 2 XSLoader::load __PACKAGE__, $VERSION;
12 }
13  
14 2 our @EXPORT_OK = qw(
15 GRND_RANDOM
16 GRND_NONBLOCK
17 getrandom
18 random_bytes
19 );
20  
21 1 ▶sub random_bytes {
Subroutine random_bytes: called CC=6 SCAR=19.9
Pod documented
22 1 my ($n) = @_;
23 1 $n |= 0;
24 1 ▶ $n >= 0 && $n <= 256
Branch: 1 branch
BranchTrueFalseTotal
$n >= 0 and $n <= 256 or croak("Argument to random_bytes() must be an integer between 0 and 256, not $n") 1 0 1
Condition33%1/3
$n >= 0 and $n <= 256
!ll&&!rl&&r
001
MC/DC0%0/2
$n >= 0 and $n <= 256
$n >= 0 $n <= 256
Truth table33%1/3
A and B
A= $n >= 0B= $n <= 256
ABresult
0X0
100
111
25 or croak "Argument to random_bytes() must be an integer between 0 and 256, not $n";
26 1 ▶ return '' if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 0 1 1
27 1 ▶ defined(my $r = getrandom(my $buf, $n))
Branch: 1 branch
BranchTrueFalseTotal
defined(my $r = &getrandom(my $buf, $n)) or die "Internal error: getrandom(\$buf, $n) failed: $!" 1 0 1
28 or die "Internal error: getrandom(\$buf, $n) failed: $!";
29 1 ▶ $r == $n
Branch: 1 branch
BranchTrueFalseTotal
$r == $n or die "Internal error: getrandom(\$buf, $n) returned $r" 1 0 1
30 or die "Internal error: getrandom(\$buf, $n) returned $r";
31 1 $buf
32 }
33  
34 2 1
35 __END__
↑ Summary GetRandom.xs »