ACME2/HTTP_Tiny.pm

filter: Statementstmt 66.6% 26 / 39 Branchbran 16.6% 1 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 60.0% 36 / 60 CC 5 SCAR 20.2
CC
5
Cov
56%
request
20.0
new
2.3
BEGIN
1.0
CRAP 7.6
« ACME2/Error.pm ↑ Summary ACME2/Authorization.pm »
1 package Net::ACME2::HTTP_Tiny;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Net::ACME2::HTTP_Tiny - HTTP client for Net::ACME
8  
9 =head1 SYNOPSIS
10  
11 use Net::ACME2::HTTP_Tiny;
12  
13 my $http = Net::ACME2::HTTP_Tiny->new();
14  
15 #NOTE: Unlike HTTP::Tiny’s method, this will die() if the HTTP
16 #session itself fails--for example, if the network connection was
17 #interrupted. These will be Net::ACME2::X::HTTP::Network instances.
18 #
19 #This also fails on HTTP errors (4xx and 5xx). The errors are
20 #instances of Net::ACME2::X::HTTP::Protocol.
21 #
22 my $resp_obj = $http->post_form( $the_url, \%the_form_post );
23  
24 =head1 DESCRIPTION
25  
26 This module largely duplicates the work of C<HTTP::Tiny::UA>, just without the
27 dependency on C<superclass.pm> (which brings in a mess of other undesirables).
28  
29 The chief benefit is that C<request()> and related methods will return
30 instances of C<HTTP::Tiny::UA::Response> rather than simple hashes.
31  
32 This also always verifies remote SSL connections and always C<die()>s if
33 either the network connection fails or the protocol indicates an error
34 (4xx or 5xx).
35  
36 =cut
37  
38 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 ▶use parent qw( HTTP::Tiny );
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 1 ▶use HTTP::Tiny::UA::Response ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 1 ▶use Net::ACME2::Constants ();
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use Net::ACME2::X ();
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 our $VERSION;
49 1 *VERSION = \$Net::ACME2::Constants::VERSION;
50  
51 #Use this to tweak SSL config, e.g., if you want to cache PublicSuffix.
52 1 our @SSL_OPTIONS;
53  
54 sub new {
55 1 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=2 SCAR=8.4
Pod documented
56  
57 $args{'SSL_options'} = {
58 1 ▶ ( $args{'SSL_options'} ? (%{ $args{'SSL_options'} }) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$args{'SSL_options'} ? : 0 1 1
59 @SSL_OPTIONS,
60 };
61  
62 1 my $self = $class->SUPER::new(
63 verify_SSL => 1,
64 %args,
65 );
66  
67 0 return $self;
68 }
69  
70 #mocked in tests
71 1 *_base_request = HTTP::Tiny->can('request');
72  
73 sub request {
74 0 ▶ my ( $self, $method, $url, $args_hr ) = @_;
Subroutine request: not called CC=4 SCAR=30.0
Pod documented
75  
76 #HTTP::Tiny clobbers $@. The clobbering is useless since the
77 #error is in the $resp variable already. Clobbering also risks
78 #action-at-a-distance problems, so prevent it here.
79  
80 #cf. eval_bug.readme
81 0 my $eval_err = $@;
82  
83 0 ▶ my $resp = _base_request( $self, $method, $url, $args_hr || () );
Condition0%0/3
$args_hr || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$args_hr || ()
$args_hr ()
Truth table0%0/3
A || B
A= $args_hrB= ()
ABresult
1X1
011
000
84  
85 0 $@ = $eval_err;
86  
87 0 my $resp_obj = HTTP::Tiny::UA::Response->new($resp);
88  
89 #cf. HTTP::Tiny docs
90 0 ▶ if ( $resp_obj->status() == 599 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp_obj->status == 599) 0 0 0
91 die Net::ACME2::X->create(
92 'HTTP::Network',
93 {
94 method => $method,
95 url => $url,
96 error => $resp_obj->content(),
97 0 redirects => $resp->{'redirects'},
98 }
99 );
100 }
101  
102 0 ▶ if ( $resp->{'status'} >= 400 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"status"} >= 400) 0 0 0
103 die Net::ACME2::X->create(
104 'HTTP::Protocol',
105 {
106 method => $method,
107 redirects => $resp->{'redirects'},
108 0 ( map { ( $_ => $resp_obj->$_() ) } qw( content status reason url headers ) ),
109 },
110 );
111 }
112  
113 0 return $resp_obj;
114 }
115  
116 1 1;
117  
« ACME2/Error.pm ↑ Summary ACME2/Authorization.pm »