| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
not $earliest_time or time >= $earliest_time
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$val && time + $val
$val
time + $val
Truth table33%1/3
A && B
A= $valB= time + $val
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 10 | return $self->{'_http'}->get($uri); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 7 | 1; | |||||||||||||||||||||||||||