File Coverage

lib/Crypt/Random/Provider/rand.pm
Criterion Covered Total %
statement 24 27 88.9
branch 3 6 50.0
condition 8 16 50.0
subroutine 5 7 71.4
pod 0 3 0.0
total 40 59 67.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -sw
2             ##
3             ## Crypt::Random::Provider::rand
4             ##
5             ## Copyright (c) 2001, Vipul Ved Prakash. All rights reserved.
6             ## This code is free software; you can redistribute it and/or modify
7             ## it under the same terms as Perl itself.
8             ##
9             ## $Id: rand.pm,v 1.2 2001/06/22 18:16:29 vipul Exp $
10              
11             package Crypt::Random::Provider::rand;
12 1     1   15 use strict;
  1         15  
  1         17  
13 1     1   16 use Math::Pari qw(pari2num);
  1         10  
  1         19  
14              
15             sub new {
16              
17 6     6 0 96     my ($class, %params) = @_;
18 6   50 65   101     my $self = { Source => $params{Source} || sub { return rand($_[0]) } };
  65         685  
19 6         236     return bless $self, $class;
20              
21             }
22              
23              
24             sub get_data {
25              
26 6     6 0 72     my ($self, %params) = @_;
27 6 50       62     $self = {} unless ref $self;
28              
29 6         54     my $size = $params{Size};
30 6   33     75     my $skip = $params{Skip} || $$self{Skip};
31              
32 6 50 66     78     if ($size && ref $size eq "Math::Pari") {
33 0         0         $size = pari2num($size);
34                 }
35              
36 6   66     153     my $bytes = $params{Length} || (int($size / 8) + 1);
37 6   50 0   61     my $source = $$self{Source} || sub { rand($_[0]) };
  0         0  
38                 
39 6         104     my($r, $read, $rt) = ('', 0);
40 6         63     while ($read < $bytes) {
41 65         600         $rt = chr(int(&$source(256)));
42 65 50 33     713         unless ($skip && $skip =~ /\Q$rt\E/) {
43 65         519             $r .= $rt; $read++;
  65         596  
44                     }
45                 }
46              
47 6         253     $r;
48              
49             }
50              
51              
52             sub available {
53              
54 0     0 0       return 1;
55              
56             }
57              
58              
59             1;
60              
61