line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Async::SPORE::Request; |
2
|
|
|
|
|
|
|
$Net::Async::SPORE::Request::VERSION = '0.003'; |
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Net::Async::SPORE::Definition - holds information about a SPORE definition |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.003 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
957
|
use URI; |
|
1
|
|
|
|
|
8241
|
|
|
1
|
|
|
|
|
36
|
|
19
|
1
|
|
|
1
|
|
977
|
use URI::QueryParam; |
|
1
|
|
|
|
|
783
|
|
|
1
|
|
|
|
|
38
|
|
20
|
1
|
|
|
1
|
|
6
|
use URI::Escape qw(uri_escape_utf8); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1112
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 METHODS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 new |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Instantiate this request. Any named parameters will be |
29
|
|
|
|
|
|
|
used to populate the environment. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
35
|
0
|
|
|
|
|
|
bless { env => { @_ } }, $class |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 env |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Returns the environment hashref. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
1
|
|
sub env { shift->{env} } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 as_request |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Returns an L object representing this |
49
|
|
|
|
|
|
|
environment. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub as_request { |
54
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
require HTTP::Request; |
57
|
0
|
|
|
|
|
|
my $uri = URI->new( |
58
|
|
|
|
|
|
|
$self->scheme . '://' . $self->server_name |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $path = $self->request_uri; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Apply our parameters |
64
|
0
|
|
|
|
|
|
my @param = @{$self->params}; |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
while(my ($k, $v) = splice @param, 0, 2) { |
66
|
0
|
0
|
|
|
|
|
unless($path =~ s/:$k/uri_escape_utf8($v)/ge) { |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$uri->query_param_append($k => $v); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$uri->path($path); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Convert this into a request |
74
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( |
75
|
|
|
|
|
|
|
$self->request_method => $uri |
76
|
|
|
|
|
|
|
); |
77
|
0
|
|
|
|
|
|
$req->protocol('HTTP/1.1'); |
78
|
0
|
0
|
|
|
|
|
$req->content($self->payload) if length $self->payload; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $env = $self->env; |
81
|
0
|
|
|
|
|
|
for my $k (grep /^HTTPS?_/, keys %$env) { |
82
|
0
|
|
|
|
|
|
my ($name) = $k =~ /^HTTPS?_(.*)/; |
83
|
0
|
|
|
|
|
|
$req->header($name => $env->{$k}); |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
return $req; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 METHODS - Environment accessors |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
These provide accessor/mutator support for the environment entries. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 request_method |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub request_method { |
97
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
98
|
0
|
0
|
|
|
|
|
return $self->env->{REQUEST_METHOD} unless @_; |
99
|
0
|
|
|
|
|
|
$self->env->{REQUEST_METHOD} = shift; |
100
|
0
|
|
|
|
|
|
return $self; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 script_name |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub script_name { |
108
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
109
|
0
|
0
|
|
|
|
|
return $self->env->{SCRIPT_NAME} unless @_; |
110
|
0
|
|
|
|
|
|
$self->env->{SCRIPT_NAME} = shift; |
111
|
0
|
|
|
|
|
|
return $self; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 path_info |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub path_info { |
119
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
120
|
0
|
0
|
|
|
|
|
return $self->env->{PATH_INFO} unless @_; |
121
|
0
|
|
|
|
|
|
$self->env->{PATH_INFO} = shift; |
122
|
0
|
|
|
|
|
|
return $self; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 request_uri |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub request_uri { |
130
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
131
|
0
|
0
|
|
|
|
|
return $self->env->{REQUEST_URI} unless @_; |
132
|
0
|
|
|
|
|
|
$self->env->{REQUEST_URI} = shift; |
133
|
0
|
|
|
|
|
|
return $self; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 server_name |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub server_name { |
141
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
142
|
0
|
0
|
|
|
|
|
return $self->env->{SERVER_NAME} unless @_; |
143
|
0
|
|
|
|
|
|
$self->env->{SERVER_NAME} = shift; |
144
|
0
|
|
|
|
|
|
return $self; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 server_port |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub server_port { |
152
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
153
|
0
|
0
|
|
|
|
|
return $self->env->{SERVER_PORT} unless @_; |
154
|
0
|
|
|
|
|
|
$self->env->{SERVER_PORT} = shift; |
155
|
0
|
|
|
|
|
|
return $self; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 query_string |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub query_string { |
163
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
164
|
0
|
0
|
|
|
|
|
return $self->env->{QUERY_STRING} unless @_; |
165
|
0
|
|
|
|
|
|
$self->env->{QUERY_STRING} = shift; |
166
|
0
|
|
|
|
|
|
return $self; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 payload |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub payload { |
174
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
175
|
0
|
0
|
|
|
|
|
return $self->env->{payload} unless @_; |
176
|
0
|
|
|
|
|
|
$self->env->{payload} = shift; |
177
|
0
|
|
|
|
|
|
return $self; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 params |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub params { |
185
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
186
|
0
|
0
|
|
|
|
|
return $self->env->{params} unless @_; |
187
|
0
|
|
|
|
|
|
$self->env->{params} = shift; |
188
|
0
|
|
|
|
|
|
return $self; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 redirections |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub redirections { |
196
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
197
|
0
|
0
|
|
|
|
|
return $self->env->{redirections} unless @_; |
198
|
0
|
|
|
|
|
|
$self->env->{redirections} = shift; |
199
|
0
|
|
|
|
|
|
return $self; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 scheme |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub scheme { |
207
|
0
|
|
|
0
|
1
|
|
my ($self) = shift; |
208
|
0
|
0
|
|
|
|
|
return $self->env->{scheme} unless @_; |
209
|
0
|
|
|
|
|
|
$self->env->{scheme} = shift; |
210
|
0
|
|
|
|
|
|
return $self; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
1; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
__END__ |