UserAgent/LWP.pm

filter: Statementstmt 73.0% 19 / 26 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 6 / 8 Podpod 100% 3 / 3 totaltotal 63.6% 28 / 44 SCAR 12.6
CC
3
Cov
61%
request
6.0
ua
6.0
BEGIN
1.0
CRAP 3.5
« UserAgent.pm ↑ Summary
1 package WebService::Async::UserAgent::LWP;
2 1 $WebService::Async::UserAgent::LWP::VERSION = '0.004';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use parent qw(WebService::Async::UserAgent);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 WebService::Async::UserAgent::LWP - make requests using L<LWP::UserAgent>
11  
12 =head1 VERSION
13  
14 version 0.004
15  
16 =head1 DESCRIPTION
17  
18 Provides a L</request> method which will use L<LWP::UserAgent> to make
19 requests and return a L<Future> containing the result. Used internally by
20 L<WebService::Async::UserAgent>.
21  
22 =cut
23  
24 1 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 =head2 new
28  
29 Instantiate.
30  
31 =cut
32  
33 1 ▶sub new { my $class = shift; bless {@_}, $class }
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34  
35 =head2 request
36  
37 Issues the request. Expects a single L<HTTP::Request> object,
38 and returns a L<Future> which will resolve to the decoded
39 response content on success, or the failure reason on failure.
40  
41 =cut
42  
43 sub request {
44 0 ▶ my $self = shift;
Subroutine request: not called CC=2 SCAR=17.9
Pod documented
45 0 my $req = shift;
46 0 my $resp = $self->ua->request($req);
47 0 ▶ return Future->new->done($resp->decoded_content) if $resp->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $resp->is_success 0 0 0
48  
49 0 my $status = join ' ', $resp->code, $resp->message;
50 0 return Future->new->fail($status, $resp, $req)
51 }
52  
53 =head2 ua
54  
55 Returns the L<LWP::UserAgent> instance.
56  
57 =cut
58  
59 0 ▶sub ua { shift->{ua} ||= LWP::UserAgent->new }
Subroutine ua: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
+(shift())->{"ua"} ||= "LWP::UserAgent"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->{"ua"} ||= "LWP::UserAgent"->new
+(shift())->{"ua"} "LWP::UserAgent"->new
Truth table0%0/3
A ||= B
A= +(shift())->{"ua"}B= "LWP::UserAgent"->new
ABresult
1X1
011
000
60  
61 1 1;
62  
63 =head1 AUTHOR
64  
65 Tom Molesworth <cpan@perlsite.co.uk>
66  
67 =head1 LICENSE
68  
69 Copyright Tom Molesworth 2012-2015. Licensed under the same terms as Perl itself.
« UserAgent.pm ↑ Summary