Source/Base.pm

filter: Statementstmt 32.0% 8 / 25 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 25.0% 2 / 8 Podpod 100% 6 / 6 totaltotal 30.1% 16 / 53 CC 6 SCAR 22.6
CC
6
Cov
22%
get_data
20.0
read
12.0
available
2.0
CRAP 9.6
↑ Summary Source/Base/Handle.pm »
1 package Crypt::Random::Source::Base;
2 # ABSTRACT: Abstract base class for L<Crypt::Random::Source> classes
3  
4 6 our $VERSION = '0.14';
5  
6 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub available { 0 }
Subroutine available: not called CC=1 SCAR=6.9
Pod documented
10  
11 0 ▶sub rank { 0 }
Subroutine rank: not called CC=1 SCAR=6.9
Pod documented
12  
13 0 ▶sub seed { }
Subroutine seed: not called CC=1 SCAR=0.0
Pod documented
14  
15 0 ▶sub get { die "abstract" }
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
16  
17 # cannibalized from IO::Scalar
18 0 ▶sub read {
Subroutine read: not called CC=3 SCAR=24.8
Pod documented
19 0 my $self = $_[0];
20 0 my $n = $_[2];
21 0 ▶ my $off = $_[3] || 0;
Condition0%0/2
$_[3] || 0
l!l
00
MC/DC0%0/1
$_[3] || 0
$_[3]
Truth table0%0/2
A
A= $_[3]
Aresult
11
00
22  
23 0 my $read = $self->get($n);
24 0 $n = length($read);
25 0 ▶ ($off ? substr($_[1], $off) : $_[1]) = $read;
Branch: 1 branch
BranchTrueFalseTotal
$off ? : 0 0 0
26 0 return $n;
27 }
28  
29 0 ▶sub get_data {
Subroutine get_data: not called CC=4 SCAR=30.0
Pod documented
30 0 my ( $self, %params ) = @_;
31  
32 0 ▶ if ( my $n = $params{Length} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $n = $params{'Length'}) { } 0 0 0
33 0 return $self->get($n);
34 } else {
35 0 my $size = $params{Size};
36  
37 0 ▶ if (ref $size && ref $size eq "Math::Pari") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $size and ref $size eq "Math::Pari") 0 0 0
Condition0%0/3
ref $size and ref $size eq "Math::Pari"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $size and ref $size eq "Math::Pari"
ref $size ref $size eq "Math::Pari"
Truth table0%0/3
A and B
A= ref $sizeB= ref $size eq "Math::Pari"
ABresult
0X0
100
111
38 0 $size = Math::Pari::pari2num($size);
39 }
40  
41 0 return $self->get( int($size / 8) + 1 );
42 }
43 }
44  
45 6 1;
46  
47 =pod
48  
49 =encoding UTF-8
50  
51 =head1 NAME
52  
53 Crypt::Random::Source::Base - Abstract base class for L<Crypt::Random::Source> classes
54  
55 =head1 VERSION
56  
57 version 0.14
58  
59 =head1 SYNOPSIS
60  
61 use Moo;
62 extends qw(Crypt::Random::Source::Base);
63  
64 =head1 DESCRIPTION
65  
66 This is an abstract base class.
67  
68 In the future it will be a role.
69  
70 =head1 METHODS
71  
72 =head2 get $n, %args
73  
74 Gets C<$n> random bytes and returns them as a string.
75  
76 This method may produce fatal errors if the source was unable to provide enough
77 data.
78  
79 =head2 read $buf, $n, [ $off ]
80  
81 This method is cannibalized from L<IO::Scalar>. It provides an L<IO::Handle>
82 work-alike.
83  
84 Note that subclasses override this to operate on a real handle directly if
85 available.
86  
87 =head2 seed @stuff
88  
89 On supporting sources this method will add C<@stuff>, whatever it may be, to
90 the random seed.
91  
92 Some sources may not support this, so be careful.
93  
94 =head2 available
95  
96 This is a class method, such that when it returns true calling C<new> without
97 arguments on the class should provide a working source of random data.
98  
99 This is use by L<Crypt::Random::Source::Factory>.
100  
101 =head2 rank
102  
103 This is a class method, with some futz value for a ranking, to help known good
104 sources be tried before known bad (slower, less available) sources.
105  
106 =head2 get_data %Params
107  
108 Provided for compatibility with L<Crypt::Random>
109  
110 =head1 SUPPORT
111  
112 Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Crypt-Random-Source>
113 (or L<bug-Crypt-Random-Source@rt.cpan.org|mailto:bug-Crypt-Random-Source@rt.cpan.org>).
114  
115 =head1 AUTHOR
116  
117 יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
118  
119 =head1 COPYRIGHT AND LICENCE
120  
121 This software is copyright (c) 2008 by Yuval Kogman.
122  
123 This is free software; you can redistribute it and/or modify it under
124 the same terms as the Perl 5 programming language system itself.
125  
126 =cut
127  
128 __END__
↑ Summary Source/Base/Handle.pm »