ACME2/Authorization.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 64 CC 2 SCAR 9.6
CC
2
Cov
0%
challenges
6.0
wildcard
2.0
identifier
2.0
CRAP 2.6
1 package Net::ACME2::Authorization;
2  
3 use strict;
4 use warnings;
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 Net::ACME2::Authorization
11  
12 =head1 DESCRIPTION
13  
14 The ACME Authorization object.
15  
16 =cut
17  
18 use parent qw( Net::ACME2::AccessorBase );
19  
20 use Call::Context ();
21  
22 use Net::ACME2::Challenge ();
23  
24 #Pre-load challenge classes.
25 use Net::ACME2::Challenge::http_01 ();
26 use Net::ACME2::Challenge::dns_01 ();
27  
28 use constant _ACCESSORS => (
29 'id',
30 'expires',
31 'status',
32 );
33  
34 =head1 ACCESSORS
35  
36 These provide text strings as defined in the ACME specification.
37  
38 =over
39  
40 =item * B<id()>
41  
42 =item * B<status()>
43  
44 =item * B<expires()>
45  
46 =back
47  
48 =head1 OTHER METHODS
49  
50 =head2 I<OBJ>->wildcard()
51  
52 Returns a Perl boolean that indicates whether the authorization is
53 for a wildcard DNS name.
54  
55 =cut
56  
57 sub wildcard {
58 my ($self) = @_;
59  
60 return !!$self->{'_wildcard'};
61 }
62  
63 =head2 I<OBJ>->identifier()
64  
65 The order’s identifier, as a hash reference.
66 The content matches the ACME specification. (NB: Wildcard
67 authorizations do B<NOT> contain the leading C<*.> in the
68 C<value>.)
69  
70 =cut
71  
72 sub identifier {
73 my ($self) = @_;
74  
75 return { %{ $self->{'_identifier'} } };
76 }
77  
78 =head2 I<OBJ>->challenges()
79  
80 The order’s challenges, as a list of L<Net::ACME2::Challenge>
81 instances. (C<http-01> challenges will be instances of
82 L<Net::ACME2::Challenge::http_01>.)
83  
84 =cut
85  
86 sub challenges {
87 my ($self) = @_;
88  
89 Call::Context::must_be_list();
90  
91 my @challenges;
92  
93 for my $c ( @{ $self->{'_challenges'} } ) {
94 my $class = 'Net::ACME2::Challenge';
95  
96 my $module_leaf = $c->{'type'};
97 $module_leaf =~ tr<-><_>;
98 $class .= "::$module_leaf";
99  
100 #Ignore unrecognized challenges.
101 next if !$class->can('new');
102  
103 push @challenges, $class->new( %$c );
104 }
105  
106 return @challenges;
107 }
108  
109 sub update {
110 my ($self, $new_hr) = @_;
111  
112 for my $name ( 'status', 'challenges' ) {
113 $self->{"_$name"} = $new_hr->{$name};
114 }
115  
116 return $self;
117 }
118  
119 1;