line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::OAuth::Request::Mojo; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
451
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
4
|
use Class::Tiny::Chained 'request'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
184
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
8
|
1
|
|
|
1
|
|
5
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
514
|
|
11
|
|
|
|
|
|
|
with 'WWW::OAuth::Request'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
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->url->to_string unless @_; |
25
|
0
|
|
|
|
|
|
require Mojo::URL; |
26
|
0
|
|
|
|
|
|
$self->request->url(Mojo::URL->new(shift)); |
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub content { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
0
|
|
|
|
|
return $self->request->body unless @_; |
33
|
0
|
|
|
|
|
|
$self->request->body(shift); |
34
|
0
|
|
|
|
|
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub content_is_form { |
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
39
|
0
|
0
|
|
|
|
|
return 0 if $self->request->content->is_multipart; |
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
|
0
|
|
|
0
|
1
|
|
sub query_pairs { shift->request->query_params->pairs } |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
1
|
|
sub body_pairs { require Mojo::Parameters; Mojo::Parameters->new(shift->request->body)->pairs } |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub header { |
50
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my $name = shift; |
52
|
0
|
0
|
|
|
|
|
croak 'No header to set/retrieve' unless defined $name; |
53
|
0
|
0
|
|
|
|
|
return $self->request->headers->header($name) unless @_; |
54
|
0
|
0
|
|
|
|
|
my @values = ref $_[0] eq 'ARRAY' ? @{$_[0]} : $_[0]; |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self->request->headers->header($name => @values); |
56
|
0
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub request_with { |
60
|
0
|
|
|
0
|
1
|
|
my ($self, $ua, $cb) = @_; |
61
|
0
|
0
|
0
|
|
|
|
croak 'Unknown user-agent object' unless blessed $ua and $ua->isa('Mojo::UserAgent'); |
62
|
0
|
|
|
|
|
|
my $tx = $ua->build_tx($self->method, $self->url, $self->request->headers->to_hash, $self->content); |
63
|
0
|
|
|
|
|
|
return $ua->start($tx, $cb); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
WWW::OAuth::Request::Mojo - HTTP Request container for Mojo::Message::Request |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SYNOPSIS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $req = WWW::OAuth::Request::Mojo->new(request => $mojo_request); |
75
|
|
|
|
|
|
|
my $tx = $req->request_with(Mojo::UserAgent->new); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L is a request container for L that |
80
|
|
|
|
|
|
|
wraps a L object, which is used by L. |
81
|
|
|
|
|
|
|
It performs the role L. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
L implements the following attributes. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 request |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $mojo_request = $req->request; |
90
|
|
|
|
|
|
|
$req = $req->request($mojo_request); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L object to authenticate. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 METHODS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L composes all methods from L, |
97
|
|
|
|
|
|
|
and implements the following new ones. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 body_pairs |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $pairs = $req->body_pairs; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Return body parameters from L"request"> as an even-sized arrayref of keys and |
104
|
|
|
|
|
|
|
values. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 content |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $content = $req->content; |
109
|
|
|
|
|
|
|
$req = $req->content('foo=1&bar=2'); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Set or return request content from L"request">. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 content_is_form |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $bool = $req->content_is_form; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Check whether L"request"> has single-part content and a C |
118
|
|
|
|
|
|
|
header of C. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 header |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $header = $req->header('Content-Type'); |
123
|
|
|
|
|
|
|
$req = $req->header(Authorization => 'foo bar'); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Set or return a request header from L"request">. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 method |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $method = $req->method; |
130
|
|
|
|
|
|
|
$req = $req->method('GET'); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Set or return request method from L"request">. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 query_pairs |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $pairs = $req->query_pairs; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Return query parameters from L"request"> as an even-sized arrayref of keys |
139
|
|
|
|
|
|
|
and values. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 request_with |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $tx = $req->request_with(Mojo::UserAgent->new); |
144
|
|
|
|
|
|
|
$req->request_with(Mojo::UserAgent->new, sub { |
145
|
|
|
|
|
|
|
my ($ua, $tx) = @_; |
146
|
|
|
|
|
|
|
... |
147
|
|
|
|
|
|
|
}); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Run request with passed L user-agent object, and return |
150
|
|
|
|
|
|
|
L object, as in L. A callback can |
151
|
|
|
|
|
|
|
be passed to perform the request non-blocking. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 url |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my $url = $req->url; |
156
|
|
|
|
|
|
|
$req = $req->url('http://example.com/api/'); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Set or return request URL from L"request">. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 BUGS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Report any issues on the public bugtracker. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AUTHOR |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Dan Book |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This software is Copyright (c) 2015 by Dan Book. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This is free software, licensed under: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 SEE ALSO |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |