File Coverage

blib/lib/WebService/Async/UserAgent.pm
Criterion Covered Total %
statement 26 27 96.3
branch 1 2 50.0
condition 2 6 33.3
subroutine 11 12 91.6
pod 1 7 14.2
total 41 54 75.9


line stmt bran cond sub pod time code
1             package WebService::Async::UserAgent;
2             # ABSTRACT: HTTP useragent abstraction for webservices
3 2     2   649 use strict;
  2         3  
  2         59  
4 2     2   6 use warnings;
  2         2  
  2         67  
5              
6             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).
32             Although there is very basic support for sync clients such as L,
33             they are untested and only there as an example. That may change in future.
34              
35             =cut
36              
37 2     2   8 use URI;
  2         1  
  2         27  
38 2     2   7 use HTTP::Request;
  2         2  
  2         35  
39 2     2   7 use HTTP::Response;
  2         2  
  2         465  
40              
41             =head1 METHODS
42              
43             =cut
44              
45             =head2 new
46              
47             Instantiate.
48              
49             =cut
50              
51 1     1 1 3423 sub new { my $class = shift; bless { @_ }, $class }
  1         4  
52              
53              
54 1     1 0 25 sub parallel { 0 }
55              
56 1     1 0 10 sub timeout { 60 }
57              
58 0     0 0 0 sub request { ... }
59              
60             sub GET {
61 1     1 0 3766 my ($self, $uri) = @_;
62 1 50       9 $uri = URI->new($uri) unless ref $uri;
63 1         5438 my $req = HTTP::Request->new(
64             GET => $uri
65             );
66 1         171 $req->header(host => $uri->host);
67 1         124 $self->request($req)
68             }
69              
70             # Back-compat
71             *get = \&GET;
72              
73 1   33 1 0 13 sub user_agent { $_[0]->{user_agent} //= "Mozilla/5.0 (Perl) " . (ref $_[0] || $_[0]) }
      33        
74              
75 1     1 0 31 sub ssl_args { () }
76              
77             1;
78              
79             __END__