| 1 | package WebService::Async::UserAgent; | ||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: HTTP useragent abstraction for webservices | ||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.004'; | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | WebService::Async::UserAgent - common API for making HTTP requests to webservices | ||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | version 0.004 | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | use strict; | ||||||||||||||||||||||||||||||
| 19 | use warnings; | ||||||||||||||||||||||||||||||
| 20 | use WebService::Async::UserAgent::NaHTTP; | ||||||||||||||||||||||||||||||
| 21 | my $ua = WebService::Async::UserAgent::NaHTTP->new(loop => $loop); | ||||||||||||||||||||||||||||||
| 22 | eval { | ||||||||||||||||||||||||||||||
| 23 | print "was OK" if $ua->get('...')->get->code == 200; | ||||||||||||||||||||||||||||||
| 24 | } or warn "Failed - $@"; | ||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | This is an early release, most things are undocumented and subject to change. | ||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | The intention is to provide an abstraction for webservice API calls without | ||||||||||||||||||||||||||||||
| 31 | hardcoding a dependency on a specific HTTP client (such as L<Net::Async::HTTP>). | ||||||||||||||||||||||||||||||
| 32 | Although there is very basic support for sync clients such as L<LWP::UserAgent>, | ||||||||||||||||||||||||||||||
| 33 | they are untested and only there as an example. That may change in future. | ||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | use HTTP::Response; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | =head2 new | ||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | Instantiate. | ||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub new { my $class = shift; bless { @_ }, $class } | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub parallel { 0 } | ||||||||||||||||||||||||||||
|
Subroutine
parallel: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | sub timeout { 60 } | ||||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub request { ... } | ||||||||||||||||||||||||||||
|
Subroutine
request: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | sub GET { | ||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | my ($self, $uri) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
GET: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | $uri = URI->new($uri) unless ref $uri; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 63 | 1 | my $req = HTTP::Request->new( | |||||||||||||||||||||||||||||
| 64 | GET => $uri | ||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||
| 66 | 1 | $req->header(host => $uri->host); | |||||||||||||||||||||||||||||
| 67 | 1 | $self->request($req) | |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | # Back-compat | ||||||||||||||||||||||||||||||
| 71 | 2 | *get = \&GET; | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub user_agent { $_[0]->{user_agent} //= "Mozilla/5.0 (Perl) " . (ref $_[0] || $_[0]) } | ||||||||||||||||||||||||||||
|
Subroutine
user_agent: called CC=3 SCAR=14.2
Pod
undocumented
Condition40%2/5
$_[0]{"user_agent"} //= 'Mozilla/5.0 (Perl) ' . (ref $_[0] || $_[0])
ref $_[0] || $_[0]
MC/DC0%0/1
$_[0]{"user_agent"} //= 'Mozilla/5.0 (Perl) ' . (ref $_[0] || $_[0])
$_[0]{"user_agent"}
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table50%1/2
A
A= $_[0]{"user_agent"}
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub ssl_args { () } | ||||||||||||||||||||||||||||
|
Subroutine
ssl_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | 2 | 1; | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||