| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | package WWW::Kickstarter::HttpClient::Lwp; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 1 |  |  | 1 |  | 3013 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 5 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 20 |  | 
| 6 | 1 |  |  | 1 |  | 3 | no autovivification; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 482 | use HTTP::Headers           qw( ); | 
|  | 1 |  |  |  |  | 5460 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 10 | 1 |  |  | 1 |  | 428 | use HTTP::Request::Common   qw( GET POST ); | 
|  | 1 |  |  |  |  | 7487 |  | 
|  | 1 |  |  |  |  | 49 |  | 
| 11 | 1 |  |  | 1 |  | 417 | use LWP::Protocol::https    qw( ); | 
|  | 1 |  |  |  |  | 78065 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 12 | 1 |  |  | 1 |  | 591 | use LWP::UserAgent          qw( ); | 
|  | 1 |  |  |  |  | 8715 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 13 | 1 |  |  | 1 |  | 4 | use WWW::Kickstarter::Error qw( my_croak ); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 271 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub new { | 
| 17 | 0 |  |  | 0 | 0 |  | my ($class, %opts) = @_; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 0 |  |  |  |  |  | my $agent = delete($opts{agent}); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 0 | 0 |  |  |  |  | if (my @unrecognized = keys(%opts)) { | 
| 22 | 0 |  |  |  |  |  | my_croak(400, "Unrecognized parameters @unrecognized"); | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 0 |  |  |  |  |  | my $http_client = LWP::UserAgent->new( | 
| 26 |  |  |  |  |  |  | default_headers => HTTP::Headers->new( | 
| 27 |  |  |  |  |  |  | Accept => 'application/json; charset=utf-8', | 
| 28 |  |  |  |  |  |  | ), | 
| 29 |  |  |  |  |  |  | env_proxy => 1, | 
| 30 |  |  |  |  |  |  | ); | 
| 31 | 0 | 0 |  |  |  |  | $http_client->agent($agent) if $agent; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 |  |  |  |  |  | my $self = bless({}, $class); | 
| 34 | 0 |  |  |  |  |  | $self->{http_client} = $http_client; | 
| 35 | 0 |  |  |  |  |  | return $self; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub request { | 
| 40 | 0 |  |  | 0 | 0 |  | my ($self, $method, $url, $req_content) = @_; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 |  |  |  |  |  | my $http_request; | 
| 43 | 0 | 0 |  |  |  |  | if ($method eq 'GET' ) { | 
|  |  | 0 |  |  |  |  |  | 
| 44 | 0 |  |  |  |  |  | $http_request = GET($url); | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | elsif ($method eq 'POST') { | 
| 47 | 0 |  |  |  |  |  | $http_request = POST($url, | 
| 48 |  |  |  |  |  |  | Content_Length => length($req_content), | 
| 49 |  |  |  |  |  |  | Content_Type   => 'application/x-www-form-urlencoded', | 
| 50 |  |  |  |  |  |  | Content        => $req_content, | 
| 51 |  |  |  |  |  |  | ); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  | else { | 
| 54 | 0 |  |  |  |  |  | my_croak(400, "Unexpected argument"); | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 0 |  |  |  |  |  | my $http_response = $self->{http_client}->request($http_request); | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 0 |  |  |  |  |  | my $status_code      = $http_response->code(); | 
| 60 | 0 |  |  |  |  |  | my $status_line      = $http_response->status_line(); | 
| 61 | 0 |  |  |  |  |  | my $content_type     = $http_response->content_type();  # Lowercase with "parameters" filtered out. | 
| 62 | 0 |  |  |  |  |  | my $content_encoding = $http_response->content_type_charset(); | 
| 63 | 0 |  |  |  |  |  | my $content          = $http_response->decoded_content( charset => 'none' ); | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 0 |  |  |  |  |  | return ( $status_code, $status_line, $content_type, $content_encoding, $content ); | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | 1; | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | __END__ |