File Coverage

blib/lib/Net/ACME/X/HTTP/Protocol.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition 5 5 100.0
subroutine 5 5 100.0
pod 0 1 0.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             package Net::ACME::X::HTTP::Protocol;
2              
3             =encoding utf-8
4              
5             =head1 NAME
6              
7             Net::ACME::X::HTTP::Protocol
8              
9             =head1 DESCRIPTION
10              
11             This exception class means that an error occurred with an HTTP
12             request, and the problem had specifically to do with something
13             that happened on the remote server, not just a general connection
14             problem. For example, this class would be suitable for use when
15             you get a 500 Internal Server Error or a 404 Not Found, but it
16             would not be suitable for use if you get a Connection Refused
17             error when trying to connect.
18              
19             =cut
20              
21 2     2   15 use strict;
  2         5  
  2         61  
22 2     2   10 use warnings;
  2         4  
  2         91  
23              
24 2     2   15 use parent qw( Net::ACME::X::HashBase );
  2         4  
  2         13  
25              
26             # In a normal HTTP response, we don't necessarily know if the body is going
27             # to be meaningful for display, so only include the first chunk.
28             #
29             #(accessed from tests)
30 2     2   105 use constant BODY_DISPLAY_SIZE => 1_024;
  2         4  
  2         369  
31              
32             #named args required:
33             #
34             # method
35             # reason
36             # url
37             # status
38             #
39             sub new {
40 4     4 0 11 my ( $self, $args_hr ) = @_;
41              
42 4         8 my $content = $args_hr->{'content'};
43 4 100 100     27 if ( defined($content) && length($content) > BODY_DISPLAY_SIZE() ) {
44 1         3 substr( $content, BODY_DISPLAY_SIZE() ) = '…';
45             }
46              
47 4   100     13 $content ||= q<>;
48              
49 4         35 return $self->SUPER::new(
50             "The response to the HTTP “$args_hr->{'method'}” request from “$args_hr->{'url'}” indicated an error ($args_hr->{'status'}, $args_hr->{'reason'}): “$content”",
51             $args_hr,
52             );
53             }
54              
55             1;