ACME/HTTP/Response.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 4 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 91.0% 51 / 56 CC 5 SCAR 9.3
CC
5
Cov
98%
links
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
« ACME/Authorization.pm ↑ Summary ACME/X/HTTP/Protocol.pm »
1 package Net::ACME::HTTP::Response;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use parent qw( HTTP::Tiny::UA::Response );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Call::Context ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use Net::ACME::X ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub die_because_unexpected {
14 4 ▶ my ($self) = @_;
Subroutine die_because_unexpected: called CC=1 SCAR=0.0
Pod undocumented
15  
16 4 die Net::ACME::X::create(
17 'UnexpectedResponse',
18 {
19 uri => $self->url(),
20 status => $self->status(),
21 reason => $self->reason(),
22 headers => $self->headers(),
23 },
24 );
25 }
26  
27 #Useful for everything but certificate issuance, apparently?
28 sub content_struct {
29 10 ▶ my ($self) = @_;
Subroutine content_struct: called CC=1 SCAR=0.0
Pod undocumented
30  
31 10 return JSON::decode_json( $self->content() );
32 }
33  
34 #A “poor man’s Link header parser” that only knows how to handle
35 #these values as described in the ACME protocol spec:
36 #a single “rel” parameter, and no extra whitespace.
37 #
38 #This returns key/value pairs. They should probably go into a hash,
39 #but I don’t see anything in the spec that says the same “rel”
40 #parameter can’t occur twice.
41 #
42 #If we need something more robust down the line,
43 #HTTP::Link::Parser::parse_single_link() may do the trick.
44 sub links {
45 8 ▶ my ($self) = @_;
Subroutine links: called CC=5 SCAR=16.1
Pod undocumented
46  
47 8 Call::Context::must_be_list();
48  
49 8 my $links_ar = $self->header('link');
50 8 ▶ if ( !ref $links_ar ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $links_ar) 5 3 8
51 5 ▶ $links_ar = [ $links_ar || () ];
Condition66%2/3
$links_ar || ()
l!l&&r!l&&!r
302
MC/DC50%1/2
$links_ar || ()
$links_ar ()
Truth table66%2/3
A || B
A= $links_arB= ()
ABresult
1X1
011
000
52 }
53  
54 8 my @resp;
55  
56 8 for my $l (@$links_ar) {
57 8 ▶ $l =~ m/\A<([^>]+)>;rel="([^"]+)"\z/ or do {
Branch: 1 branch
BranchTrueFalseTotal
$l =~ /\A<([^>]+)>;rel="([^"]+)"\z/ or do { warn "Unrecognized link: \342\200\234$l\342\200\235"; next } 1 7 8
58 1 warn "Unrecognized link: “$l”";
59 1 next;
60 };
61  
62 7 push @resp, $2, $1;
63 }
64  
65 8 return @resp;
66 }
67  
68 8 1;
« ACME/Authorization.pm ↑ Summary ACME/X/HTTP/Protocol.pm »