OAuth/Request/HTTP_Request.pm

filter: Statementstmt 86.5% 45 / 52 Branchbran 65.0% 13 / 20 Conditioncond 33.3% 2 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 91.6% 11 / 12 Podpod 100% 6 / 6 totaltotal 78.0% 78 / 100 SCAR 27.1
CC
13
Cov
77%
request_with
30.0
content_is_form
4.0
header
3.0
CRAP 15.1
« OAuth/Util.pm ↑ Summary OAuth/Request/Basic.pm »
1 package WWW::OAuth::Request::HTTP_Request;
2  
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 2 ▶use Class::Tiny::Chained 'request';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 with 'WWW::OAuth::Request';
12  
13 2 our $VERSION = '1.000';
14  
15 sub method {
16 3 ▶ my $self = shift;
Subroutine method: called CC=2 SCAR=6.9
Pod documented
17 3 ▶ return $self->request->method unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 1 3
18 1 $self->request->method(shift);
19 1 return $self;
20 }
21  
22 sub url {
23 7 ▶ my $self = shift;
Subroutine url: called CC=2 SCAR=6.9
Pod documented
24 7 ▶ return $self->request->uri->as_string unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 3 7
25 3 $self->request->uri(shift);
26 3 return $self;
27 }
28  
29 sub content {
30 7 ▶ my $self = shift;
Subroutine content: called CC=2 SCAR=6.9
Pod documented
31 7 ▶ return $self->request->content unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 3 7
32 3 $self->request->content(shift);
33 3 return $self;
34 }
35  
36 sub content_is_form {
37 5 ▶ my $self = shift;
Subroutine content_is_form: called CC=4 SCAR=13.9
Pod documented
38 5 my @parts = $self->request->parts;
39 5 ▶ return 0 if @parts;
Branch: 1 branch
BranchTrueFalseTotal
if @parts 1 4 5
40 4 my $content_type = $self->request->headers->content_type;
41 4 ▶ return 0 unless defined $content_type and $content_type =~ m!application/x-www-form-urlencoded!i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content_type and $content_type =~ m[application/x-www-form-urlencoded]i 2 2 4
Condition66%2/3
defined $content_type and $content_type =~ m[application/x-www-form-urlencoded]i
!ll&&!rl&&r
022
MC/DC50%1/2
defined $content_type and $content_type =~ m[application/x-www-form-urlencoded]i
defined $content_type $content_type =~ m[application/x-www-form-urlencoded]i
Truth table66%2/3
A and B
A= defined $content_typeB= $content_type =~ m[application/x-www-form-urlencoded]i
ABresult
0X0
100
111
42 2 return 1;
43 }
44  
45 sub header {
46 13 ▶ my $self = shift;
Subroutine header: called CC=3 SCAR=11.0
Pod documented
47 13 my $name = shift;
48 13 ▶ croak 'No header to set/retrieve' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 13 13
49 13 ▶ return scalar $self->request->header($name) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 7 6 13
50 6 $self->request->header($name => shift);
51 6 return $self;
52 }
53  
54 sub request_with {
55 0 ▶ my ($self, $ua) = @_;
Subroutine request_with: not called CC=5 SCAR=34.0
Pod documented
56 0 ▶ croak 'Invalid user-agent object' unless blessed $ua;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($ua) 0 0 0
57 0 ▶ if ($ua->isa('LWP::UserAgent') or $ua->isa('HTTP::Thin')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ua->isa('LWP::UserAgent') or $ua->isa('HTTP::Thin')) { } 0 0 0
elsif ($ua->isa('Net::Async::HTTP')) { } 0 0 0
Condition0%0/3
$ua->isa("LWP::UserAgent") or $ua->isa("HTTP::Thin")
l!l&&r!l&&!r
000
MC/DC0%0/2
$ua->isa("LWP::UserAgent") or $ua->isa("HTTP::Thin")
$ua->isa("LWP::UserAgent") $ua->isa("HTTP::Thin")
Truth table0%0/3
A or B
A= $ua->isa("LWP::UserAgent")B= $ua->isa("HTTP::Thin")
ABresult
1X1
011
000
58 0 return $ua->request($self->request);
59 } elsif ($ua->isa('Net::Async::HTTP')) {
60 0 return $ua->do_request(request => $self->request);
61 } else {
62 0 my $class = blessed $ua;
63 0 croak "Unknown user-agent class $class";
64 }
65 }
66  
67 2 1;
68  
69 =head1 NAME
70  
71 WWW::OAuth::Request::HTTP_Request - HTTP Request container for HTTP::Request
72  
73 =head1 SYNOPSIS
74  
75 my $req = WWW::OAuth::Request::HTTP_Request->new(request => $http_request);
76 $req->request_with(LWP::UserAgent->new);
77  
78 =head1 DESCRIPTION
79  
80 L<WWW::OAuth::Request::HTTP_Request> is a request container for L<WWW::OAuth>
81 that wraps a L<HTTP::Request> object, which can be used by several user-agents
82 like L<LWP::UserAgent>, L<HTTP::Thin>, and L<Net::Async::HTTP>. It performs the
83 role L<WWW::OAuth::Request>.
84  
85 =head1 ATTRIBUTES
86  
87 L<WWW::OAuth::Request::HTTP_Request> implements the following attributes.
88  
89 =head2 request
90  
91 my $http_request = $req->request;
92 $req = $req->request(HTTP::Request->new(GET => $url));
93  
94 L<HTTP::Request> object to authenticate.
95  
96 =head1 METHODS
97  
98 L<WWW::OAuth::Request::HTTP_Request> composes all methods from
99 L<WWW::OAuth::Request>, and implements the following new ones.
100  
101 =head2 content
102  
103 my $content = $req->content;
104 $req = $req->content('foo=1&bar=2');
105  
106 Set or return request content from L</"request">.
107  
108 =head2 content_is_form
109  
110 my $bool = $req->content_is_form;
111  
112 Check whether L</"request"> has single-part content and a C<Content-Type>
113 header of C<application/x-www-form-urlencoded>.
114  
115 =head2 header
116  
117 my $header = $req->header('Content-Type');
118 $req = $req->header(Authorization => 'Basic foobar');
119  
120 Set or return a request header from L</"request">.
121  
122 =head2 method
123  
124 my $method = $req->method;
125 $req = $req->method('GET');
126  
127 Set or return request method from L</"request">.
128  
129 =head2 request_with
130  
131 $http_response = $req->request_with(LWP::UserAgent->new);
132  
133 Run request with passed user-agent object, and return L<HTTP::Response> object.
134 User-agent may be L<LWP::UserAgent>, L<HTTP::Thin>, or L<Net::Async::HTTP>. If
135 run with L<Net::Async::HTTP>, the return value is a L<Future> yielding the
136 L<HTTP::Response> object as in L<< "do_request" in Net::Async::HTTP|Net::Async::HTTP/"$response = $http->do_request( %args )->get" >>.
137  
138 =head2 url
139  
140 my $url = $req->url;
141 $req = $req->url('http://example.com/api/');
142  
143 Set or return request URL from L</"request">.
144  
145 =head1 BUGS
146  
147 Report any issues on the public bugtracker.
148  
149 =head1 AUTHOR
150  
151 Dan Book <dbook@cpan.org>
152  
153 =head1 COPYRIGHT AND LICENSE
154  
155 This software is Copyright (c) 2015 by Dan Book.
156  
157 This is free software, licensed under:
158  
159 The Artistic License 2.0 (GPL Compatible)
160  
161 =head1 SEE ALSO
162  
163 L<LWP::UserAgent>, L<HTTP::Thin>, L<Net::Async::HTTP>
« OAuth/Util.pm ↑ Summary OAuth/Request/Basic.pm »