Beacon.pm

filter: Statementstmt 89.0% 49 / 55 Branchbran 50.0% 5 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 80.2% 73 / 91 SCAR 21.4
CC
8
Cov
80%
current_record
3.5
next_record
3.3
previous_record
3.1
CRAP 8.5
↑ Summary Beacon/Record.pm »
1 package NIST::Beacon;
2  
3 # ABSTRACT: A Perl module for querying NIST's randomness beacon.
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = "1.001";
9  
10 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use NIST::Beacon::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶has _agent => (is => 'ro', default => sub { LWP::UserAgent->new(agent => 'NIST-Beacon') });
Subroutine __ANON__: called CC=1 SCAR=0.0
16 4 ▶has _url => (is => 'ro', default => sub { 'https://beacon.nist.gov/rest/record/' });
Subroutine __ANON__: called CC=1 SCAR=0.0
17  
18 sub latest_record {
19 1 ▶ my $self = shift;
Subroutine latest_record: called CC=2 SCAR=7.1
Pod documented
20 1 my $url = $self->_url . 'last';
21 1 my $response = $self->_agent->get($url);
22  
23 1 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 1 0 1
24 1 my $data = XMLin($response->decoded_content);
25 1 return NIST::Beacon::Record->new($data);
26 }
27 else {
28 0 return;
29 }
30 }
31  
32 sub previous_record {
33 2 ▶ my $self = shift;
Subroutine previous_record: called CC=3 SCAR=11.3
Pod documented
34 2 ▶ my $time = shift || time;
Condition66%2/3
shift() || time
l!l&&r!l&&!r
110
MC/DC0%0/2
shift() || time
shift() time
Truth table66%2/3
A || B
A= shift()B= time
ABresult
1X1
011
000
35 2 my $url = $self->_url . 'previous/' . $time;
36 2 my $response = $self->_agent->get($url);
37  
38 2 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 2 0 2
39 2 my $data = XMLin($response->decoded_content);
40 2 return NIST::Beacon::Record->new($data);
41 }
42 else {
43 0 return;
44 }
45 }
46  
47 sub current_record {
48 1 ▶ my $self = shift;
Subroutine current_record: called CC=3 SCAR=12.6
Pod documented
49 1 ▶ my $time = shift || time - 60;
Condition33%1/3
shift() || time - 60
l!l&&r!l&&!r
010
MC/DC0%0/2
shift() || time - 60
shift() time - 60
Truth table33%1/3
A || B
A= shift()B= time - 60
ABresult
1X1
011
000
50 1 my $url = $self->_url . $time;
51 1 my $response = $self->_agent->get($url);
52  
53 1 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 1 1
54 0 my $data = XMLin($response->decoded_content);
55 0 return NIST::Beacon::Record->new($data);
56 }
57 else {
58 1 return;
59 }
60 }
61  
62 sub next_record {
63 1 ▶ my $self = shift;
Subroutine next_record: called CC=3 SCAR=12.0
Pod documented
64 1 ▶ my $time = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $time = shift() or return 0 1 1
65 1 my $url = $self->_url . 'next/' . $time;
66 1 my $response = $self->_agent->get($url);
67  
68 1 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 1 1
69 0 my $data = XMLin($response->decoded_content);
70 0 return NIST::Beacon::Record->new($data);
71 }
72 else {
73 1 return;
74 }
75 }
76  
77 4 1;
78  
79 __END__
↑ Summary Beacon/Record.pm »