File Coverage

blib/lib/Net/ACME/Authorization.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Net::ACME::Authorization;
2              
3             =pod
4              
5             =encoding utf-8
6              
7             =head1 NAME
8              
9             Net::ACME::Authorization - fulfilled ACME authorization object
10              
11             =head1 SYNOPSIS
12              
13             use Net::ACME::Authorization ();
14              
15             my $authz = Net::ACME::Authorization->new(
16             status => 'valid', #or “invalid”
17             challenges => [ @list_of_challenge_objects ],
18             );
19              
20             my @challenge_objs = $authz->challenges();
21              
22             my $payload;
23             while (!$cert) {
24             if ($need_retry->is_time_to_poll()) {
25             $cert = $need_retry->poll();
26             }
27              
28             sleep 1;
29             }
30              
31             =cut
32              
33             #NOTE: For now, this assumes a domain name.
34             #Might be useful moving forward to separate out other types
35             #of authz as per ACME spec expansion. (As of April 2016 only
36             #domain names are handled.)
37              
38 1     1   57709 use strict;
  1         1  
  1         22  
39 1     1   4 use warnings;
  1         1  
  1         17  
40              
41 1     1   463 use Call::Context ();
  1         184  
  1         13  
42              
43 1     1   387 use Net::ACME::Utils ();
  0            
  0            
44             use Net::ACME::X ();
45              
46             my $CHALLENGE_CLASS = 'Net::ACME::Challenge';
47              
48             sub new {
49             my ( $class, %opts ) = @_;
50              
51             my $self = {
52             _status => $opts{'status'} || die('Need “status”!'),
53             _challenges => $opts{'challenges'},
54             };
55              
56             if ( $opts{'challenges'} ) {
57             for my $c ( 0 .. $#{ $opts{'challenges'} } ) {
58             my $challenge = $opts{'challenges'}[$c];
59              
60             if ( !Net::ACME::Utils::thing_isa($challenge, $CHALLENGE_CLASS) ) {
61             die Net::ACME::X::create( 'InvalidParameter', "“challenges” index $c ($challenge) is not an instance of “$CHALLENGE_CLASS”!" );
62             }
63             }
64             }
65              
66             return bless $self, $class;
67             }
68              
69             sub status {
70             my ($self) = @_;
71             return $self->{'_status'};
72             }
73              
74             sub challenges {
75             my ($self) = @_;
76              
77             Call::Context::must_be_list();
78              
79             return @{ $self->{'_challenges'} };
80             }
81              
82             1;