File Coverage

blib/lib/Random/Any.pm
Criterion Covered Total %
statement 18 22 81.8
branch 6 14 42.8
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 28 40 70.0


line stmt bran cond sub pod time code
1             package Random::Any;
2              
3 2     2   550203 use strict 'subs', 'vars';
  2         5  
  2         992  
4             #use warnings;
5              
6             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7             our $DATE = '2026-01-20'; # DATE
8             our $DIST = 'Random-Any'; # DIST
9             our $VERSION = '0.006'; # VERSION
10              
11             my $warn;
12             my $sub;
13              
14             sub rand(;$) { ## no critic: Subroutines::ProhibitSubroutinePrototypes
15 1     1 1 427087 $sub->(@_);
16             }
17              
18             sub import {
19 1     1   10 my $pkg = shift;
20              
21 1         3 my $caller = caller();
22              
23 1         8 while (@_) {
24 1         2 my $arg = shift;
25 1 50       5 if ($arg eq '-warn') {
    50          
26 0         0 $warn = shift;
27             } elsif ($arg eq 'rand') {
28 1         3 *{"$caller\::rand"} = \&rand;
  1         7  
29             } else {
30 0         0 die "'$_' is not exported by " . __PACKAGE__;
31             }
32             }
33              
34 1 50       5 $warn = $ENV{PERL_RANDOM_ANY_WARN} unless defined $warn;
35 1 50       2 $warn = 1 unless defined $warn;
36              
37 1 50       3 unless ($sub) {
38 1 50       4 if (eval { require Data::Entropy::Algorithms; 1 }) {
  1         825  
  1         22508  
39 1         2251 $sub = \&Data::Entropy::Algorithms::rand;
40             } else {
41 0 0         warn __PACKAGE__ . ": Data::Entropy::Algorithms is not available: $@, falling back on builtin rand()" if $warn;
42 0           $sub = \&CORE::rand;
43             }
44             }
45             }
46              
47             1;
48             # ABSTRACT: Try to use Data::Entropy::Algorithms::rand(), fallback on builtin rand()
49              
50             __END__