Lite/Agent.pm

filter: Statementstmt 81.2% 26 / 32 Branchbran 100% 2 / 2 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 80.0% 8 / 10 Podpod 100% 5 / 5 totaltotal 80.6% 50 / 62 SCAR 16.4
CC
5
Cov
81%
filter_request
4.0
new
2.1
request
2.0
CRAP 5.2
« Lite/Response.pm ↑ Summary Lite/SignatureMethod.pm »
1 package OAuth::Lite::Agent;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use List::MoreUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10 9 ▶ my ($class, $ua) = @_;
Subroutine new: called CC=2 SCAR=7.6
Pod documented
11 9 ▶ my $self = bless {
Condition33%1/3
$ua || 'LWP::UserAgent'->new
l!l&&r!l&&!r
090
MC/DC0%0/2
$ua || 'LWP::UserAgent'->new
$ua 'LWP::UserAgent'->new
Truth table33%1/3
A || B
A= $uaB= 'LWP::UserAgent'->new
ABresult
1X1
011
000
12 ua => $ua || LWP::UserAgent->new,
13 }, $class;
14 9 return $self;
15 }
16  
17 sub agent {
18 8 ▶ my ($self, $agent) = @_;
Subroutine agent: called CC=1 SCAR=0.0
Pod documented
19 8 $self->{ua}->agent($agent);
20 }
21  
22 sub request {
23 0 ▶ my ($self, $req) = @_;
Subroutine request: not called CC=1 SCAR=6.9
Pod documented
24 0 $req = $self->filter_request($req);
25 0 my $res = $self->{ua}->request($req);
26 0 return $self->filter_response($res);
27 }
28  
29 sub filter_request {
30 4 ▶ my ($self, $req) = @_;
Subroutine filter_request: called CC=4 SCAR=13.9
Pod documented
31 4 ▶ my $accept_encoding = $req->header('Accept-Encoding') || '';
Condition100%2/2
$req->header('Accept-Encoding') || ''
l!l
31
MC/DC100%1/1
$req->header('Accept-Encoding') || ''
$req->header('Accept-Encoding')
Truth table100%2/2
A
A= $req->header('Accept-Encoding')
Aresult
11
00
32 4 my @encodings = split(/\s*,\s*/, $accept_encoding);
33 4 ▶ if (@encodings == 0 || List::MoreUtils::none { $_ eq 'gzip' } @encodings) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (@encodings == 0 or &List::MoreUtils::none(sub { $_ eq "gzip"; } , @encodings)) 2 2 4
Condition100%3/3
@encodings == 0 or &List::MoreUtils::none(sub { $_ eq "gzip"; } , @encodings)
l!l&&r!l&&!r
112
MC/DC100%2/2
@encodings == 0 or &List::MoreUtils::none(sub { $_ eq "gzip"; } , @encodings)
@encodings == 0 &List::MoreUtils::none(sub { $_ eq "gzip"; } , @encodings)
Truth table100%3/3
A or B
A= @encodings == 0B= &List::MoreUtils::none(sub { $_ eq "gzip"; } , @encodings)
ABresult
1X1
011
000
34 2 push(@encodings, 'gzip');
35 }
36 4 $req->header('Accept-Encoding' => join(', ', @encodings));
37 4 return $req;
38 }
39  
40  
41 sub filter_response {
42 0 ▶ my ($self, $res) = @_;
Subroutine filter_response: not called CC=1 SCAR=6.9
Pod documented
43 0 return $res;
44 }
45  
46 5 1;
47  
48 =head1 NAME
49  
50 OAuth::Lite::Agent - default agent class
51  
52 =head1 SYNOPSIS
53  
54 $agent = OAuth::Lite::Agent->new;
55 my $res = $agent->request($req);
56  
57 =head1 DESCRIPTION
58  
59 Default user agent for OAuth::Lite::Consuemr.
60  
61 =head1 METHODS
62  
63 =head2 new
64  
65 constructor.
66  
67 OAuth::Lite::Agent->new();
68  
69 You can pass custom agent, that is required to implement
70 'request' and 'agent' methods corresponding to the same named methods of LWP::UserAgnet.
71  
72 my $custom_agent = LWP::UserAgent->new(timeout => 10);
73 OAuth::Lite::Agent->new($custom_agent);
74  
75 =head2 agent
76  
77 agent setter
78  
79 $agent->agent("MyAgent/1.0.0");
80  
81 =head2 request
82  
83 As same as LWP::UserAgent, pass HTTP::Request object
84 and returns HTTP::Response object.
85  
86 $res = $agent->request($req);
87  
88 =head2 filter_request
89  
90 filter the HTTP::Request object before request.
91  
92 =head2 filter_response
93  
94 filter the HTTP::Response object after request.
95  
96 =head1 SEE ALSO
97  
98 http://oauth.pbwiki.com/ProblemReporting
99  
100 =head1 AUTHOR
101  
102 Lyo Kato, C<lyo.kato _at_ gmail.com>
103  
104 =head1 COPYRIGHT AND LICENSE
105  
106 This library is free software; you can redistribute it and/or modify
107 it under the same terms as Perl itself, either Perl version 5.8.6 or,
108 at your option, any later version of Perl 5 you may have available.
109  
110 =cut
111  
« Lite/Response.pm ↑ Summary Lite/SignatureMethod.pm »