File Coverage

blib/lib/WebService/PayPal/PaymentsAdvanced/Response/FromHTTP.pm
Criterion Covered Total %
statement 30 30 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 10 10 100.0
pod 0 1 0.0
total 44 46 95.6


line stmt bran cond sub pod time code
1             package WebService::PayPal::PaymentsAdvanced::Response::FromHTTP;
2              
3 7     7   145177 use Moo;
  7         10794  
  7         50  
4              
5 7     7   4059 use namespace::autoclean;
  7         11811  
  7         62  
6              
7             our $VERSION = '0.000028';
8              
9 7     7   1233 use MooX::StrictConstructor;
  7         14029  
  7         88  
10 7     7   31667 use Types::Standard qw( HashRef InstanceOf );
  7         83463  
  7         80  
11 7     7   7454 use Types::URI qw( Uri );
  7         102830  
  7         70  
12 7     7   2572 use URI ();
  7         20  
  7         133  
13 7     7   487 use URI::QueryParam;
  7         865  
  7         173  
14 7     7   3702 use WebService::PayPal::PaymentsAdvanced::Error::HTTP ();
  7         32  
  7         1743  
15              
16             # Don't use HasParams role as we want to build params rather than require them.
17              
18             has params => (
19             is => 'lazy',
20             isa => HashRef,
21             init_arg => undef,
22             );
23              
24             has _http_response => (
25             is => 'ro',
26             isa => InstanceOf ['HTTP::Response'],
27             init_arg => 'http_response',
28             required => 1,
29             handles => { _code => 'code', _content => 'content', },
30             );
31              
32             has _request_uri => (
33             init_arg => 'request_uri',
34             is => 'ro',
35             isa => Uri,
36             coerce => 1,
37             required => 1,
38             );
39              
40             sub BUILD {
41 19     19 0 63617 my $self = shift;
42             return
43 19 100 66     139 if $self->_http_response->is_success
44             && !$self->_http_response->header('X-Died');
45              
46 4         60 WebService::PayPal::PaymentsAdvanced::Error::HTTP
47             ->throw_from_http_response(
48             http_response => $self->_http_response,
49             request_uri => $self->_request_uri,
50             );
51             }
52              
53             sub _build_params {
54 14     14   1918 my $self = shift;
55 14         295 my $results = URI->new( '?' . $self->_content );
56 14         1639 return $results->query_form_hash;
57             }
58              
59             1;
60              
61             =pod
62              
63             =encoding UTF-8
64              
65             =head1 NAME
66              
67             WebService::PayPal::PaymentsAdvanced::Response::FromHTTP - Response object for WebService::PayPal::PaymentsAdvanced instantiated from HTTP::Response object
68              
69             =head1 VERSION
70              
71             version 0.000028
72              
73             =head1 DESCRIPTION
74              
75             This module provides an interface for extracting returned params from an
76             L<HTTP::Response> object. You won't need to this module directly if you are
77             using L<PayPal::PaymentsAdvanced/create_secure_token>.
78              
79             Throws a L<WebService::PayPal::PaymentsAdvanced::Error::HTTP> exception if the
80             HTTP request was not successful.
81              
82             =head1 OBJECT INSTANTIATION
83              
84             The following parameters can be supplied to C<new()> when creating a new object.
85              
86             =head2 Required Parameters
87              
88             =head3 http_response
89              
90             An L<HTTP::Response> object.
91              
92             =head2 Methods
93              
94             =head3 params
95              
96             Returns a C<HashRef> of parameters which have been extracted from the
97             L<HTTP::Response> object.
98              
99             =head1 SUPPORT
100              
101             Bugs may be submitted through L<https://github.com/maxmind/webservice-paypal-paymentsadvanced/issues>.
102              
103             =head1 AUTHOR
104              
105             Olaf Alders <olaf@wundercounter.com>
106              
107             =head1 COPYRIGHT AND LICENSE
108              
109             This software is copyright (c) 2022 by MaxMind, Inc.
110              
111             This is free software; you can redistribute it and/or modify it under
112             the same terms as the Perl 5 programming language system itself.
113              
114             =cut
115              
116             __END__
117             # ABSTRACT: Response object for WebService::PayPal::PaymentsAdvanced instantiated from HTTP::Response object
118