File Coverage

blib/lib/Crypt/URandom/MonkeyPatch.pm
Criterion Covered Total %
statement 27 27 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 9 9 100.0
pod 1 1 100.0
total 41 41 100.0


line stmt bran cond sub pod time code
1             package Crypt::URandom::MonkeyPatch;
2              
3             # ABSTRACT: override core rand function to use system random sources
4              
5 2     2   283169 use v5.8.0;
  2         7  
6              
7 2     2   10 use strict;
  2         3  
  2         80  
8 2     2   10 use warnings;
  2         4  
  2         130  
9              
10 2     2   1029 use Crypt::URandom 0.55 qw( urandom );
  2         8286  
  2         166  
11              
12 2     2   13 use constant SIZE => 1 << 31;
  2         3  
  2         145  
13 2     2   11 use constant MASK => SIZE - 1;
  2         3  
  2         119  
14              
15             our $VERSION = 'v0.1.4';
16              
17 2     2   857 use version 0.77; $VERSION = version->declare($VERSION);
  2         4209  
  2         15  
18              
19             BEGIN {
20              
21 2     2   536 *CORE::GLOBAL::rand = \&rand;
22             }
23              
24             sub rand(;$) {
25 4   100 4 1 146099 my $a = shift || 1;
26 4         13 my ($b) = unpack( "N", urandom(4) ) & MASK;
27 4 100       100 if ( $ENV{CRYPT_URANDOM_MONKEYPATCH_DEBUG} ) {
28 1         4 my ( $package, $filename, $line ) = caller;
29 1         49 print STDERR __PACKAGE__ . "::urandom used from ${package} line ${line}\n";
30             }
31 4         23 return $a * $b / SIZE;
32             }
33              
34              
35             1;
36              
37             __END__