ACME/RetryAfter.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 6 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 81.4% 57 / 70 CC 8 SCAR 7.7
CC
8
Cov
90%
new
3.1
is_time_to_poll
3.0
_consume_retry_after_value
2.1
CRAP 2.2
« ACME/Error.pm ↑ Summary ACME/HTTP_Tiny.pm »
1 package Net::ACME::RetryAfter;
2  
3 #----------------------------------------------------------------------
4 # A base class for modules that handle the 202 status with Retry-After
5 # header, as described in the ACME protocol spec.
6 #----------------------------------------------------------------------
7  
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 ▶use Net::ACME::HTTP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod undocumented
14 8 my ( $class, %opts ) = @_;
15  
16 8 ▶ my $uri = $opts{'uri'} or do {
Branch: 1 branch
BranchTrueFalseTotal
my $uri = $opts{"uri"} or do { die "\342\200\234Net::ACME::RetryAfter\342\200\235 requires a \342\200\234uri\342\200\235!" } 8 0 8
17 0 die( sprintf "“%s” requires a “uri”!", __PACKAGE__ );
18 };
19  
20 8 my $self = bless { _uri => $uri }, $class;
21  
22 8 ▶ if ( $opts{'retry_after'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"retry_after"}) 4 4 8
23 4 $self->_consume_retry_after_value( $opts{'retry_after'} );
24 }
25  
26 8 return $self;
27 }
28  
29 3 ▶sub uri { return (shift)->{'_uri'}; }
Subroutine uri: called CC=1 SCAR=0.0
Pod undocumented
30  
31 9 ▶sub is_time_to_poll {
Subroutine is_time_to_poll: called CC=3 SCAR=11.0
Pod undocumented
32 9 my ($self) = @_;
33  
34 9 my $earliest_time = $self->{'_next_retry_time'};
35  
36 9 ▶ return 1 if !$earliest_time || ( time >= $earliest_time );
Branch: 1 branch
BranchTrueFalseTotal
if not $earliest_time or time >= $earliest_time 4 5 9
Condition100%3/3
not $earliest_time or time >= $earliest_time
l!l&&r!l&&!r
225
MC/DC100%2/2
not $earliest_time or time >= $earliest_time
not $earliest_time time >= $earliest_time
Truth table100%3/3
not(A) or B
A= not $earliest_timeB= time >= $earliest_time
ABresult
1X1
011
000
37  
38 5 return 0;
39 }
40  
41 10 ▶sub poll {
Subroutine poll: called CC=2 SCAR=6.9
Pod undocumented
42 10 my ($self) = @_;
43  
44 10 my $resp = $self->_http_get( $self->{'_uri'} );
45  
46 10 ▶ if ( $resp->status() == 202 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->status == 202) 3 7 10
47 3 $self->_consume_retry_after_value( $resp->header('retry-after') );
48 3 return undef;
49 }
50  
51 7 return scalar $self->_handle_non_202_poll($resp);
52 }
53  
54 #https://ietf-wg-acme.github.io/acme/#certificate-issuance
55 7 ▶sub _consume_retry_after_value {
Subroutine _consume_retry_after_value: called CC=2 SCAR=7.6
56 7 my ( $self, $val ) = @_;
57  
58 7 ▶ $self->{'_next_retry_time'} = $val && ( time + $val );
Condition33%1/3
$val && time + $val
!ll&&!rl&&r
007
MC/DC0%0/2
$val && time + $val
$val time + $val
Truth table33%1/3
A && B
A= $valB= time + $val
ABresult
0X0
100
111
59  
60 7 return;
61 }
62  
63 10 ▶sub _http_get {
Subroutine _http_get: called CC=2 SCAR=7.0
64 10 my ( $self, $uri ) = @_;
65  
66 10 ▶ $self->{'_http'} ||= Net::ACME::HTTP->new();
Condition66%2/3
$self->{"_http"} ||= "Net::ACME::HTTP"->new
l!l&&r!l&&!r
730
MC/DC0%0/2
$self->{"_http"} ||= "Net::ACME::HTTP"->new
$self->{"_http"} "Net::ACME::HTTP"->new
Truth table66%2/3
A ||= B
A= $self->{"_http"}B= "Net::ACME::HTTP"->new
ABresult
1X1
011
000
67  
68 10 return $self->{'_http'}->get($uri);
69 }
70  
71 7 1;
« ACME/Error.pm ↑ Summary ACME/HTTP_Tiny.pm »