| 1 | package HTTP::AnyUA::Backend::Furl; | ||||||||||||||
| 2 | # ABSTRACT: A unified programming interface for Furl | ||||||||||||||
| 3 | |||||||||||||||
| 4 | |||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 1 | our $VERSION = '0.904'; # VERSION | |||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | ▶ | use parent 'HTTP::AnyUA::Backend'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | ▶ | use HTTP::AnyUA::Util; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | |||||||||||||||
| 15 | 0 | ▶ | sub request { | ||||||||||||
|
Subroutine
request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 16 | 0 | my $self = shift; | |||||||||||||
| 17 | 0 | my ($method, $url, $args) = @_; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 0 | local $args->{content} = HTTP::AnyUA::Util::coderef_content_to_string($args->{content}); | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | my $request = HTTP::AnyUA::Util::native_to_http_request(@_); | |||||||||||||
| 22 | 0 | my $ua_resp = $self->ua->request($request); | |||||||||||||
| 23 | |||||||||||||||
| 24 | 0 | return $self->_munge_response($ua_resp, $args->{data_callback}); | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 0 | ▶ | sub _munge_response { | ||||||||||||
|
Subroutine
_munge_response: not called CC=4 SCAR=30.0
| |||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||
| 29 | 0 | my $ua_resp = shift; | |||||||||||||
| 30 | 0 | my $data_cb = shift; | |||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | my $resp = { | |||||||||||||
| 33 | success => !!$ua_resp->is_success, | ||||||||||||||
| 34 | url => $ua_resp->request->uri->as_string, | ||||||||||||||
| 35 | status => $ua_resp->code, | ||||||||||||||
| 36 | reason => $ua_resp->message, | ||||||||||||||
| 37 | headers => HTTP::AnyUA::Util::http_headers_to_native($ua_resp->headers), | ||||||||||||||
| 38 | }; | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | ▶ | $resp->{protocol} = $ua_resp->protocol if $ua_resp->protocol; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | |||||||||||||||
| 42 | 0 | ▶ | if ($resp->{headers}{'x-internal-response'}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 43 | 0 | HTTP::AnyUA::Util::internal_exception($ua_resp->content, $resp); | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | elsif ($data_cb) { | ||||||||||||||
| 46 | 0 | $data_cb->($ua_resp->content, $resp); | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | else { | ||||||||||||||
| 49 | 0 | $resp->{content} = $ua_resp->content; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | return $resp; | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 1 | 1; | |||||||||||||
| 56 | |||||||||||||||
| 57 | __END__ | ||||||||||||||