| 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
| |||||||||||||||||||||
| 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
MC/DC0%0/2
shift() || time
shift()
time
Truth table66%2/3
A || B
A= shift()B= time
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
MC/DC0%0/2
shift() || time - 60
shift()
time - 60
Truth table33%1/3
A || B
A= shift()B= time - 60
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||