blib/lib/Sys/GetRandom/FFI.pm

filter: Statementstmt 100% 29 / 29 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 97.5% 39 / 40 CC 3 SCAR 4.7
CC
3
Cov
97%
getrandom
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
↑ Summary
1 package Sys::GetRandom::FFI;
2  
3 # ABSTRACT: get random bytes from the system
4  
5 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use FFI::Platypus 2.00;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use constant GRND_NONBLOCK => 0x0001;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use constant GRND_RANDOM => 0x0002;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our @EXPORT_OK = qw( GRND_RANDOM GRND_NONBLOCK getrandom );
17  
18 1 our $VERSION = 'v0.1.1';
19  
20  
21 1 ▶sub getrandom( $size, $opts = 0 ) {
Subroutine getrandom: called CC=3 SCAR=11.0
Pod documented
22  
23 1 state $ffi = FFI::Platypus->new(
24 api => 2,
25 lib => undef, # libc
26 );
27  
28 1 state $random = $ffi->function( getrandom => [ 'string', 'size_t', 'int' ] => 'size_t' );
29  
30 1 my $buffer = "\0" x $size;
31 1 my $res = $random->call( $buffer, $size, $opts );
32  
33 1 ▶ return $res != -1 ? $buffer : undef;
Branch: 1 branch
BranchTrueFalseTotal
$res != -1 ? : 1 0 1
34 }
35  
36 1 1;
37  
38 __END__
↑ Summary