Random/Provider/File.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 58.3% 7 / 12 Conditioncond 35.0% 7 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 3 totaltotal 63.5% 61 / 96 CC 14 SCAR 22.2
CC
14
Cov
72%
get_data
15.5
new
6.0
_defaultsource
2.0
CRAP 9.2
« Random/Provider/Win32API.pm ↑ Summary Random/Provider/rand.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Crypt::Random::Provider::File;
4 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Math::Pari qw(pari2num);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '1.57';
9  
10 0 ▶sub _defaultsource {
Subroutine _defaultsource: not called CC=1 SCAR=6.9
11 0 return;
12 }
13  
14  
15 1701 ▶sub new {
Subroutine new: called CC=4 SCAR=17.9
Pod undocumented
16  
17 1701 my ($class, %args) = @_;
18 1701 ▶ my $self = { Source => $args{File} || $args{Device} || $args{Filename} || $class->_defaultsource() };
Condition33%3/9
$args{'File'} || $args{'Device'} || $args{'Filename'} || $class->_defaultsource
l!l&&r!l&&!r
017010
$args{"File"} or $args{"Device"} or $args{"Filename"}
l!l&&r!l&&!r
001701
$args{"File"} or $args{"Device"}
l!l&&r!l&&!r
001701
MC/DC0%0/4
$args{'File'} || $args{'Device'} || $args{'Filename'} || $class->_defaultsource
$args{"File"} $args{"Device"} $args{"Filename"} $class->_defaultsource
Truth table20%1/5
A or B or C || D
A= $args{"File"}B= $args{"Device"}C= $args{"Filename"}D= $class->_defaultsource
ABCDresult
1XXX1
01XX1
001X1
00011
00000
19 1701 return bless $self, $class;
20  
21 }
22  
23  
24 1701 ▶sub get_data {
Subroutine get_data: called CC=11 SCAR=27.4
Pod undocumented
25  
26 1701 my ($self, %params) = @_;
27 1701 ▶ $self = {} unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1701 1701
28  
29 1701 my $size = $params{Size};
30 1701 ▶ my $skip = $params{Skip} || $$self{Skip} || '';
Condition40%2/5
$params{'Skip'} || $self->{'Skip'} || ''
l!l
01701
$params{"Skip"} or $self->{"Skip"}
l!l&&r!l&&!r
001701
MC/DC0%0/2
$params{'Skip'} || $self->{'Skip'} || ''
$params{"Skip"} $self->{"Skip"}
Truth table33%1/3
A or B
A= $params{"Skip"}B= $self->{"Skip"}
ABresult
1X1
011
000
31 1701 my $q_skip = quotemeta($skip);
32  
33 1701 ▶ if ($size && ref $size eq "Math::Pari") {
Branch: 1 branch
BranchTrueFalseTotal
if ($size and ref $size eq "Math::Pari") 0 1701 1701
Condition33%1/3
$size and ref $size eq "Math::Pari"
!ll&&!rl&&r
017010
MC/DC0%0/2
$size and ref $size eq "Math::Pari"
$size ref $size eq "Math::Pari"
Truth table33%1/3
A and B
A= $sizeB= ref $size eq "Math::Pari"
ABresult
0X0
100
111
34 0 $size = pari2num($size);
35 }
36  
37 1701 ▶ my $bytes = $params{Length} || (int($size / 8) + 1);
Condition33%1/3
$params{'Length'} || int($size / 8) + 1
l!l&&r!l&&!r
017010
MC/DC0%0/2
$params{'Length'} || int($size / 8) + 1
$params{'Length'} int($size / 8) + 1
Truth table33%1/3
A || B
A= $params{'Length'}B= int($size / 8) + 1
ABresult
1X1
011
000
38  
39 1701 sysopen RANDOM, $$self{Source}, O_RDONLY;
40  
41 1701 my($r, $read, $rt) = ('', 0);
42 1701 ▶ while ($read < $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read < $bytes) 1701 1701 3402
43 1701 my $howmany = sysread RANDOM, $rt, $bytes - $read;
44 1701 ▶ next unless $howmany;
Branch: 1 branch
BranchTrueFalseTotal
unless $howmany 0 1701 1701
45 1701 ▶ if ($howmany == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($howmany == -1) 0 1701 1701
46 0 croak "Error while reading from $$self{Source}. $!"
47 }
48 1701 ▶ $rt =~ s/[$q_skip]//g if $skip;
Branch: 1 branch
BranchTrueFalseTotal
if $skip 0 1701 1701
49 1701 $r .= $rt;
50 1701 $read = length $r;
51 }
52  
53 1701 $r;
54  
55 }
56  
57  
58 704 ▶sub available {
Subroutine available: called CC=1 SCAR=0.0
Pod undocumented
59 704 my ($class) = @_;
60 704 return -e $class->_defaultsource();
61 }
62  
63  
64 4 1;
65  
« Random/Provider/Win32API.pm ↑ Summary Random/Provider/rand.pm »