File Coverage

blib/lib/WebService/PayPal/PaymentsAdvanced/Response/FromHTTP.pm
Criterion Covered Total %
statement 33 33 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 11 11 100.0
pod 0 1 0.0
total 48 50 96.0


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