line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::OAuth::Request::HTTP_Request; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
585
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
5
|
use Class::Tiny::Chained 'request'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
304
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
6
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
596
|
|
11
|
|
|
|
|
|
|
with 'WWW::OAuth::Request'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.000'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub method { |
16
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
17
|
0
|
0
|
|
|
|
|
return $self->request->method unless @_; |
18
|
0
|
|
|
|
|
|
$self->request->method(shift); |
19
|
0
|
|
|
|
|
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub url { |
23
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
24
|
0
|
0
|
|
|
|
|
return $self->request->uri->as_string unless @_; |
25
|
0
|
|
|
|
|
|
$self->request->uri(shift); |
26
|
0
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub content { |
30
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
31
|
0
|
0
|
|
|
|
|
return $self->request->content unless @_; |
32
|
0
|
|
|
|
|
|
$self->request->content(shift); |
33
|
0
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub content_is_form { |
37
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
38
|
0
|
|
|
|
|
|
my @parts = $self->request->parts; |
39
|
0
|
0
|
|
|
|
|
return 0 if @parts; |
40
|
0
|
|
|
|
|
|
my $content_type = $self->request->headers->content_type; |
41
|
0
|
0
|
0
|
|
|
|
return 0 unless defined $content_type and $content_type =~ m!application/x-www-form-urlencoded!i; |
42
|
0
|
|
|
|
|
|
return 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub header { |
46
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
my $name = shift; |
48
|
0
|
0
|
|
|
|
|
croak 'No header to set/retrieve' unless defined $name; |
49
|
0
|
0
|
|
|
|
|
return scalar $self->request->header($name) unless @_; |
50
|
0
|
|
|
|
|
|
$self->request->header($name => shift); |
51
|
0
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub request_with { |
55
|
0
|
|
|
0
|
1
|
|
my ($self, $ua) = @_; |
56
|
0
|
0
|
|
|
|
|
croak 'Invalid user-agent object' unless blessed $ua; |
57
|
0
|
0
|
0
|
|
|
|
if ($ua->isa('LWP::UserAgent') or $ua->isa('HTTP::Thin')) { |
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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 is a request container for L |
81
|
|
|
|
|
|
|
that wraps a L object, which can be used by several user-agents |
82
|
|
|
|
|
|
|
like L, L, and L. It performs the |
83
|
|
|
|
|
|
|
role L. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L 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 object to authenticate. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 METHODS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
L composes all methods from |
99
|
|
|
|
|
|
|
L, 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 |
113
|
|
|
|
|
|
|
header of C. |
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 object. |
134
|
|
|
|
|
|
|
User-agent may be L, L, or L. If |
135
|
|
|
|
|
|
|
run with L, the return value is a L yielding the |
136
|
|
|
|
|
|
|
L 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 |
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, L, L |