← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:09 2015

Filename/var/www/foswiki11/lib/Foswiki/Request.pm
StatementsExecuted 1382 statements in 11.4ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
20733152.30ms5.24msFoswiki::Request::::paramFoswiki::Request::param
111767µs6.30msFoswiki::Request::::BEGIN@37Foswiki::Request::BEGIN@37
533139µs385µsFoswiki::Request::::queryStringFoswiki::Request::queryString
333104µs491µsFoswiki::Request::::urlFoswiki::Request::url
62180µs135µsFoswiki::Request::::headerFoswiki::Request::header
44327µs27µsFoswiki::Request::::actionFoswiki::Request::action
11120µs20µsFoswiki::Request::::newFoswiki::Request::new
64420µs20µsFoswiki::Request::::pathInfoFoswiki::Request::pathInfo
11116µs33µsFoswiki::Request::::BEGIN@29Foswiki::Request::BEGIN@29
22216µs75µsFoswiki::Request::::userAgentFoswiki::Request::userAgent
22215µs15µsFoswiki::Request::::deleteFoswiki::Request::delete
11114µs21µsFoswiki::Request::::BEGIN@30Foswiki::Request::BEGIN@30
11113µs32µsFoswiki::Request::::BEGIN@38Foswiki::Request::BEGIN@38
22211µs11µsFoswiki::Request::::remoteAddressFoswiki::Request::remoteAddress
11110µs26µsFoswiki::Request::::BEGIN@35Foswiki::Request::BEGIN@35
3337µs7µsFoswiki::Request::::remoteUserFoswiki::Request::remoteUser
1114µs4µsFoswiki::Request::::BEGIN@32Foswiki::Request::BEGIN@32
1114µs4µsFoswiki::Request::::uriFoswiki::Request::uri
1114µs4µsFoswiki::Request::::BEGIN@36Foswiki::Request::BEGIN@36
1113µs3µsFoswiki::Request::::methodFoswiki::Request::method
0000s0sFoswiki::Request::::base_actionFoswiki::Request::base_action
0000s0sFoswiki::Request::::bodyParamFoswiki::Request::bodyParam
0000s0sFoswiki::Request::::cookieFoswiki::Request::cookie
0000s0sFoswiki::Request::::cookiesFoswiki::Request::cookies
0000s0sFoswiki::Request::::deleteAllFoswiki::Request::deleteAll
0000s0sFoswiki::Request::::httpFoswiki::Request::http
0000s0sFoswiki::Request::::httpsFoswiki::Request::https
0000s0sFoswiki::Request::::loadFoswiki::Request::load
0000s0sFoswiki::Request::::protocolFoswiki::Request::protocol
0000s0sFoswiki::Request::::queryParamFoswiki::Request::queryParam
0000s0sFoswiki::Request::::refererFoswiki::Request::referer
0000s0sFoswiki::Request::::saveFoswiki::Request::save
0000s0sFoswiki::Request::::secureFoswiki::Request::secure
0000s0sFoswiki::Request::::serverPortFoswiki::Request::serverPort
0000s0sFoswiki::Request::::tmpFileNameFoswiki::Request::tmpFileName
0000s0sFoswiki::Request::::uploadFoswiki::Request::upload
0000s0sFoswiki::Request::::uploadInfoFoswiki::Request::uploadInfo
0000s0sFoswiki::Request::::uploadsFoswiki::Request::uploads
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2
3=begin TML
4
5---+!! package Foswiki::Request
6
7Class to encapsulate request data.
8
9Fields:
10 * =action= action requested (view, edit, save, ...)
11 * =cookies= hashref whose keys are cookie names and values
12 are CGI::Cookie objects
13 * =headers= hashref whose keys are header name
14 * =method= request method (GET, HEAD, POST)
15 * =param= hashref of parameters, both query and body ones
16 * =param_list= arrayref with parameter names in received order
17 * =path_info= path_info of request (eg. /WebName/TopciName)
18 * =remote_address= Client's IP address
19 * =remote_user= Remote HTTP authenticated user
20 * =secure= Boolean value about use of encryption
21 * =server_port= Port that the webserver listens on
22 * =uploads= hashref whose keys are parameter name of uploaded
23 files
24 * =uri= the request uri
25
26=cut
27
28package Foswiki::Request;
29234µs250µs
# spent 33µs (16+17) within Foswiki::Request::BEGIN@29 which was called: # once (16µs+17µs) by Foswiki::Engine::CLI::BEGIN@23 at line 29
use strict;
# spent 33µs making 1 call to Foswiki::Request::BEGIN@29 # spent 17µs making 1 call to strict::import
30235µs228µs
# spent 21µs (14+7) within Foswiki::Request::BEGIN@30 which was called: # once (14µs+7µs) by Foswiki::Engine::CLI::BEGIN@23 at line 30
use warnings;
# spent 21µs making 1 call to Foswiki::Request::BEGIN@30 # spent 7µs making 1 call to warnings::import
31
32244µs14µs
# spent 4µs within Foswiki::Request::BEGIN@32 which was called: # once (4µs+0s) by Foswiki::Engine::CLI::BEGIN@23 at line 32
use CGI ();
# spent 4µs making 1 call to Foswiki::Request::BEGIN@32
3319µsour @ISA = ('CGI');
34
35228µs242µs
# spent 26µs (10+16) within Foswiki::Request::BEGIN@35 which was called: # once (10µs+16µs) by Foswiki::Engine::CLI::BEGIN@23 at line 35
use Assert;
# spent 26µs making 1 call to Foswiki::Request::BEGIN@35 # spent 16µs making 1 call to Assert::import
36225µs14µs
# spent 4µs within Foswiki::Request::BEGIN@36 which was called: # once (4µs+0s) by Foswiki::Engine::CLI::BEGIN@23 at line 36
use Error ();
# spent 4µs making 1 call to Foswiki::Request::BEGIN@36
372191µs16.30ms
# spent 6.30ms (767µs+5.53) within Foswiki::Request::BEGIN@37 which was called: # once (767µs+5.53ms) by Foswiki::Engine::CLI::BEGIN@23 at line 37
use IO::File ();
# spent 6.30ms making 1 call to Foswiki::Request::BEGIN@37
3822.38ms251µs
# spent 32µs (13+19) within Foswiki::Request::BEGIN@38 which was called: # once (13µs+19µs) by Foswiki::Engine::CLI::BEGIN@23 at line 38
use CGI::Util qw(rearrange);
# spent 32µs making 1 call to Foswiki::Request::BEGIN@38 # spent 19µs making 1 call to Exporter::import
39
40=begin TML
41
42---++ ClassMethod new([$initializer])
43
44Constructs a Foswiki::Request object.
45 * =$initializer= - may be a filehandle or hashref.
46 * If it's a filehandle, it'll be used to reload the Foswiki::Request
47 object. See =save= method. Note: Restore only parameters
48 * It can be a hashref whose keys are parameter names. Values may be
49 arrayref's to multivalued parameters. Same note as above.
50
51=cut
52
53
# spent 20µs within Foswiki::Request::new which was called: # once (20µs+0s) by Foswiki::Engine::__ANON__[/var/www/foswiki11/lib/Foswiki/Engine.pm:77] at line 68 of /var/www/foswiki11/lib/Foswiki/Engine.pm
sub new {
5411µs my ( $proto, $initializer ) = @_;
55
561200ns my $this;
57
581800ns my $class = ref($proto) || $proto;
59
6019µs $this = {
61 action => '',
62 cookies => {},
63 headers => {},
64 method => undef,
65 param => {},
66 param_list => [],
67 path_info => '',
68 remote_address => '',
69 remote_user => undef,
70 secure => 0,
71 server_port => undef,
72 uploads => {},
73 uri => '',
74 };
75
7615µs bless $this, $class;
77
7811µs if ( ref($initializer) eq 'HASH' ) {
79 while ( my ( $key, $value ) = each %$initializer ) {
80 $this->param(
81 -name => $key,
82 -value => ref($value) eq 'ARRAY' ? [@$value] : [$value]
83 );
84 }
85 }
86 elsif ( ref($initializer) && UNIVERSAL::isa( $initializer, 'GLOB' ) ) {
87 $this->load($initializer);
88 }
8915µs return $this;
90}
91
92=begin TML
93
94---++ ObjectMethod action([$action]) -> $action
95
96
97Gets/Sets action requested (view, edit, save, ...)
98
99=cut
100
101
# spent 27µs within Foswiki::Request::action which was called 4 times, avg 7µs/call: # once (9µs+0s) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki.pm:267] at line 267 of /var/www/foswiki11/lib/Foswiki.pm # once (8µs+0s) by Foswiki::generateHTTPHeaders at line 1033 of /var/www/foswiki11/lib/Foswiki.pm # once (7µs+0s) by Foswiki::Engine::CLI::preparePath at line 86 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm # once (2µs+0s) by Foswiki::UI::handleRequest at line 179 of /var/www/foswiki11/lib/Foswiki/UI.pm
sub action {
10244µs my ( $this, $action ) = @_;
10342µs if ( defined $action ) {
104
105 # Record the very first action set in this request. It will be required
106 # later if a redirect cache overlays this request.
10711µs $this->{base_action} = $action unless defined $this->{base_action};
10813µs $ENV{FOSWIKI_ACTION} = $this->{action} = $action;
10915.88ms return $action;
110 }
111 else {
112319µs return $this->{action};
113 }
114
115}
116
117=begin TML
118
119---++ ObjectMethod base_action() -> $action
120
121Get the first action ever set in this request object. This remains
122unchanged even if a request cache is unwrapped on to of this request.
123The idea is that callers can always find out the action that initiated
124the HTTP request. This is required for (for example) checking access
125controls.
126
127=cut
128
129sub base_action {
130 my $this = shift;
131 return defined $this->{base_action}
132 ? $this->{base_action}
133 : $this->action();
134}
135
136=begin TML
137
138---++ ObjectMethod method( [ $method ] ) -> $method
139
140Sets/Gets request method (GET, HEAD, POST).
141
142=cut
143
144
# spent 3µs within Foswiki::Request::method which was called: # once (3µs+0s) by Foswiki::Engine::CLI::prepareConnection at line 61 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm
sub method {
14515µs return @_ == 1 ? $_[0]->{method} : ( $_[0]->{method} = $_[1] );
146}
147
148=begin TML
149
150---++ ObjectMethod pathInfo( [ $path ] ) -> $path
151
152Sets/Gets request path info.
153
154Called without parameters returns current pathInfo.
155
156There is a =path_info()= alias for compatibility with CGI.
157
158=cut
159
16012µs*path_info = \&pathInfo;
161
162
# spent 20µs within Foswiki::Request::pathInfo which was called 6 times, avg 3µs/call: # 3 times (12µs+0s) by Foswiki::Request::url at line 250, avg 4µs/call # once (4µs+0s) by Foswiki::UI::handleRequest at line 224 of /var/www/foswiki11/lib/Foswiki/UI.pm # once (3µs+0s) by Foswiki::new at line 1860 of /var/www/foswiki11/lib/Foswiki.pm # once (2µs+0s) by Foswiki::Plugin::load at line 196 of /var/www/foswiki11/lib/Foswiki/Plugin.pm
sub pathInfo {
163627µs return @_ == 1 ? $_[0]->{path_info} : ( $_[0]->{path_info} = $_[1] );
164}
165
166=begin TML
167
168---++ ObjectMethod protocol() -> $protocol
169
170Returns 'https' if secure connection. 'http' otherwise.
171
172=cut
173
174# SMELL : review this
175sub protocol {
176 return $_[0]->secure ? 'https' : 'http';
177}
178
179=begin TML
180
181---++ ObjectMethod uri( [$uri] ) -> $uri
182
183Gets/Sets request uri.
184
185=cut
186
187
# spent 4µs within Foswiki::Request::uri which was called: # once (4µs+0s) by Foswiki::generateHTTPHeaders at line 1034 of /var/www/foswiki11/lib/Foswiki.pm
sub uri {
18816µs return @_ == 1 ? $_[0]->{uri} : ( $_[0]->{uri} = $_[1] );
189}
190
191=begin TML
192
193---++ ObjectMethod queryString() -> $query_string
194
195Returns query_string part of request uri, if any.
196
197=query_string()= alias provided for compatibility with CGI.
198
199=cut
200
2011500ns*query_string = \&queryString;
202
203
# spent 385µs (139+246) within Foswiki::Request::queryString which was called 5 times, avg 77µs/call: # 3 times (88µs+151µs) by Foswiki::Request::url at line 279, avg 80µs/call # once (31µs+53µs) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki.pm:244] at line 244 of /var/www/foswiki11/lib/Foswiki.pm # once (20µs+42µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1864 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
sub queryString {
20452µs my $this = shift;
20551µs my @params;
206512µs563µs foreach my $name ( $this->param ) {
# spent 63µs making 5 calls to Foswiki::Request::param, avg 13µs/call
2071017µs1027µs my $key = Foswiki::urlEncode($name);
# spent 27µs making 10 calls to Foswiki::urlEncode, avg 3µs/call
2081017µs1017µs push @params,
# spent 17µs making 10 calls to Foswiki::urlEncode, avg 2µs/call
2091034µs10138µs map { $key . "=" . Foswiki::urlEncode( defined $_ ? $_ : '' ) }
# spent 138µs making 10 calls to Foswiki::Request::param, avg 14µs/call
210 $this->param($name);
211 }
212521µs return join( ';', @params );
213}
214
215=begin TML
216
217---++ ObjectMethod url( [-full => 1,
218 -base => 1,
219 -absolute => 1,
220 -relative => 1,
221 -path => 1,
222 -query => 1] ) -> $url
223
224Returns many url info.
225 * If called without parameters or with -full => 1 returns full url, e.g.
226 http://mysite.net/view
227 * If called with -base => 1 returns base url, e.g. http://fosiki.org
228 * -absolute => 1 returns absolute action path, e.g. /cgi-bin/view
229 * -relative => 1 returns relative action path, e.g. view
230 * -path => 1, -query => 1 also includes path info and query string
231 respectively
232
233Reasonably compatible with CGI corresponding method. Doesn't support
234-rewrite. See Item5914.
235
236=cut
237
238
# spent 491µs (104+387) within Foswiki::Request::url which was called 3 times, avg 164µs/call: # once (40µs+144µs) by Foswiki::Plugin::load at line 196 of /var/www/foswiki11/lib/Foswiki/Plugin.pm # once (35µs+122µs) by Foswiki::new at line 1767 of /var/www/foswiki11/lib/Foswiki.pm # once (30µs+121µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1863 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
sub url {
23935µs my ( $this, @p ) = @_;
240
241318µs361µs my ( $relative, $absolute, $full, $base, $path_info, $query ) = rearrange(
# spent 61µs making 3 calls to CGI::Util::rearrange, avg 20µs/call
242 [
243 qw(RELATIVE ABSOLUTE FULL BASE), [qw(PATH PATH_INFO)],
244 [qw(QUERY_STRING QUERY)],
245 ],
246 @p
247 );
2483700ns my $url;
24933µs $full++ if $base || !( $relative || $absolute );
250312µs312µs my $path = $this->pathInfo;
# spent 12µs making 3 calls to Foswiki::Request::pathInfo, avg 4µs/call
2513600ns my $name;
252
253310µs if ( defined $Foswiki::cfg{ScriptUrlPaths}{ $this->{action} } ) {
254
255 # When this is set, it is the complete script path including prefix/suffix.
256 $name = $Foswiki::cfg{ScriptUrlPaths}{ $this->{action} };
257 }
258 else {
259 $name = $Foswiki::cfg{ScriptUrlPath} . '/' . $this->{action};
260
261 # Don't add suffix if no script is used.
262 $name .= $Foswiki::cfg{ScriptSuffix} if $name;
263 }
26436µs $name =~ s(//+)(/)g;
26533µs if ($full) {
266211µs475µs my $vh = $this->header('X-Forwarded-Host') || $this->header('Host');
# spent 75µs making 4 calls to Foswiki::Request::header, avg 19µs/call
26724µs $url =
268 $vh ? $this->protocol . '://' . $vh : $Foswiki::cfg{DefaultUrlHost};
2692500ns return $url if $base;
27022µs $url .= $name;
271 }
272 elsif ($relative) {
273 ($url) = $name =~ m{([^/]+)$};
274 }
275 elsif ($absolute) {
276 $url = $name;
277 }
27831µs $url .= $path if $path_info && defined $path;
27939µs3239µs my $queryString = $this->queryString();
# spent 239µs making 3 calls to Foswiki::Request::queryString, avg 80µs/call
28031µs $url .= '?' . $queryString if $query && $queryString;
28131µs $url = '' unless defined $url;
282
283313µs return $url;
284}
285
286=begin TML
287
288---++ ObjectMethod secure( [$secure] ) -> $secure
289
290Gets/Sets connection's secure flag.
291
292=cut
293
294sub secure {
295 return @_ == 1 ? $_[0]->{secure} : ( $_[0]->{secure} = $_[1] );
296}
297
298=begin TML
299
300---++ ObjectMethod remoteAddress( [$ip] ) -> $ip
301
302Gets/Sets client IP address.
303
304=remote_addr()= alias for compatibility with CGI.
305
306=cut
307
3081400ns*remote_addr = \&remoteAddress;
309
310
# spent 11µs within Foswiki::Request::remoteAddress which was called 2 times, avg 5µs/call: # once (7µs+0s) by Foswiki::logEvent at line 2267 of /var/www/foswiki11/lib/Foswiki.pm # once (4µs+0s) by Foswiki::Engine::CLI::prepareConnection at line 60 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm
sub remoteAddress {
311212µs return @_ == 1
312 ? $_[0]->{remote_address}
313 : ( $_[0]->{remote_address} = $_[1] );
314}
315
316=begin TML
317
318---++ ObjectMethod remoteUser( [$userName] ) -> $userName
319
320Gets/Sets remote user's name.
321
322=remote_user()= alias for compatibility with CGI.
323
324=cut
325
3261400ns*remote_user = \&remoteUser;
327
328
# spent 7µs within Foswiki::Request::remoteUser which was called 3 times, avg 2µs/call: # once (3µs+0s) by Foswiki::Engine::CLI::prepareHeaders at line 80 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm # once (2µs+0s) by Foswiki::LoginManager::ApacheLogin::getUser at line 144 of /var/www/foswiki11/lib/Foswiki/LoginManager/ApacheLogin.pm # once (2µs+0s) by Foswiki::UI::__ANON__[/var/www/foswiki11/lib/Foswiki/UI.pm:318] at line 306 of /var/www/foswiki11/lib/Foswiki/UI.pm
sub remoteUser {
329313µs return @_ == 1 ? $_[0]->{remote_user} : ( $_[0]->{remote_user} = $_[1] );
330}
331
332=begin TML
333
334---++ ObjectMethod serverPort( [$userName] ) -> $userName
335
336Gets/Sets server user's name.
337
338=server_port()= alias for compatibility with CGI.
339
340=cut
341
3421400ns*server_port = \&serverPort;
343
344sub serverPort {
345 return @_ == 1 ? $_[0]->{server_port} : ( $_[0]->{server_port} = $_[1] );
346}
347
348=begin TML
349
350---++ ObjectMethod queryParam( [-name => $name, -value => $value |
351 -name => $name, -values => [ $v1, $v2, ... ] |
352 $name, $v1, $v2, ... |
353 name, [ $v1, $v2, ... ]
354 ] ) -> @paramNames | @values | $firstValue
355
356This methos is used by engines, during its prepare phase. Should not be used
357anywhere else. Since bodyParam must exist and it has different semantics from
358param method, this one exists for symmetry, and could be modified in the
359future, so it could be possible to get query and body parameters independently.
360
361=cut
362
363sub queryParam {
364 my $this = shift;
365 return if $this->method && $this->method eq 'POST';
366 return $this->param(@_);
367}
368
369=begin TML
370
371---++ ObjectMethod bodyParam( [-name => $name, -value => $value |
372 -name => $name, -values => [ $v1, $v2, ... ] |
373 $name, $v1, $v2, ... |
374 name, [ $v1, $v2, ... ]
375 ] ) -> @paramNames | @values | $firstValue
376
377Adds parameters passed within request body to the object. Should be called
378only by engines. Otherwise use param() method.
379
380=cut
381
382sub bodyParam {
383 my $this = shift;
384 return $this->param(@_);
385}
386
387=begin TML
388
389---++ ObjectMethod param( [-name => $name, -value => $value |
390 -name => $name, -values => [ $v1, $v2, ... ] |
391 $name, $v1, $v2, ... |
392 name, [ $v1, $v2, ... ]
393 ] ) -> @paramNames | @values | $firstValue
394
395 * Called without parameters returns all parameter names
396 * Called only with parameter name or with -name => 'name'
397 * In list context returns all associated values (maybe empty list)
398 * In scalar context returns first value (maybe undef)
399 * Called with name and list of values or with
400 -name => 'name', -value => 'value' or -name => 'name', -values => [ ... ]
401 sets parameter value
402
403Resonably compatible with CGI.
404
405=cut
406
407
# spent 5.24ms (2.30+2.94) within Foswiki::Request::param which was called 207 times, avg 25µs/call: # 45 times (815µs+1.15ms) by Foswiki::getSkin at line 1375 of /var/www/foswiki11/lib/Foswiki.pm, avg 44µs/call # 45 times (389µs+374µs) by Foswiki::getSkin at line 1396 of /var/www/foswiki11/lib/Foswiki.pm, avg 17µs/call # 41 times (335µs+446µs) by Foswiki::Search::searchWeb at line 277 of /var/www/foswiki11/lib/Foswiki/Search.pm, avg 19µs/call # 18 times (196µs+254µs) by Foswiki::If::OP_dollar::evaluate at line 35 of /var/www/foswiki11/lib/Foswiki/If/OP_dollar.pm, avg 25µs/call # 12 times (105µs+138µs) by Foswiki::If::OP_defined::evaluate at line 33 of /var/www/foswiki11/lib/Foswiki/If/OP_defined.pm, avg 20µs/call # 10 times (69µs+70µs) by Foswiki::Request::queryString at line 209, avg 14µs/call # 5 times (34µs+30µs) by Foswiki::Request::queryString at line 206, avg 13µs/call # 3 times (29µs+50µs) by Foswiki::URLPARAM at line 47 of /var/www/foswiki11/lib/Foswiki/Macros/URLPARAM.pm, avg 26µs/call # 3 times (26µs+33µs) by Foswiki::REVINFO at line 17 of /var/www/foswiki11/lib/Foswiki/Macros/REVINFO.pm, avg 20µs/call # 2 times (26µs+68µs) by Foswiki::Engine::CLI::prepareQueryParameters at line 67 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm, avg 47µs/call # once (41µs+33µs) by Foswiki::UI::View::view at line 265 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (25µs+34µs) by Foswiki::Plugins::DirectedGraphPlugin::initPlugin at line 147 of /var/www/foswiki11/lib/Foswiki/Plugins/DirectedGraphPlugin.pm # once (20µs+30µs) by Foswiki::UI::View::view at line 165 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (21µs+28µs) by Foswiki::UI::View::view at line 268 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (19µs+29µs) by Foswiki::Plugins::WysiwygPlugin::modifyHeaderHandler at line 293 of /var/www/foswiki11/lib/Foswiki/Plugins/WysiwygPlugin.pm # once (18µs+25µs) by Foswiki::Plugins::load at line 134 of /var/www/foswiki11/lib/Foswiki/Plugins.pm # once (11µs+14µs) by Foswiki::LoginManager::makeLoginManager at line 85 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm # once (11µs+11µs) by Foswiki::UI::View::view at line 90 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (10µs+12µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1859 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (10µs+11µs) by Foswiki::UI::handleRequest at line 216 of /var/www/foswiki11/lib/Foswiki/UI.pm # once (8µs+13µs) by Foswiki::Plugins::WysiwygPlugin::beforeCommonTagsHandler at line 281 of /var/www/foswiki11/lib/Foswiki/Plugins/WysiwygPlugin.pm # once (9µs+10µs) by Foswiki::new at line 1828 of /var/www/foswiki11/lib/Foswiki.pm # once (9µs+10µs) by Foswiki::UI::View::view at line 228 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (8µs+10µs) by Foswiki::UI::View::view at line 102 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (7µs+8µs) by Foswiki::UI::View::view at line 91 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (7µs+9µs) by Foswiki::Plugins::TablePlugin::Core::_parseAttributes at line 293 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (8µs+8µs) by Foswiki::UI::View::view at line 247 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (7µs+8µs) by Foswiki::LoginManager::loadSession at line 470 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm # once (6µs+7µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1860 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (6µs+7µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1872 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (5µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1861 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (6µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1878 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (5µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1882 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
sub param {
408207272µs my ( $this, @p ) = @_;
409
410207957µs2072.94ms my ( $key, @value ) = rearrange( [ 'NAME', [qw(VALUE VALUES)] ], @p );
# spent 2.94ms making 207 calls to CGI::Util::rearrange, avg 14µs/call
411
41220793µs return @{ $this->{param_list} } unless defined $key;
41320057µs if ( defined $value[0] ) {
41423µs push @{ $this->{param_list} }, $key
415 unless exists $this->{param}{$key};
41622µs $this->{param}{$key} = ref $value[0] eq 'ARRAY' ? $value[0] : [@value];
417 }
418200469µs if ( defined $this->{param}{$key} ) {
419 return wantarray
420 ? @{ $this->{param}{$key} }
421 : $this->{param}{$key}->[0];
422 }
423 else {
424141499µs return wantarray ? () : undef;
425 }
426}
427
428=begin TML
429
430---++ ObjectMethod cookie($name [, $value, $path, $secure, $expires]) -> $value
431
432 * If called without parameters returns a list of cookie names.
433 * If called only with =$name= parameter returns value of cookie
434 with that name or undef if it doesn't exist.
435 * If called with defined $value and other parameters returns a
436 CGI::Cookie object created with those parameters. Doesn't
437 store this new created cookie within request object. This way
438 for compatibility with CGI.
439
440=cut
441
442sub cookie {
443 eval { require CGI::Cookie; 1 } or throw Error::Simple($@);
444 my ( $this, @p ) = @_;
445 my ( $name, $value, $path, $secure, $expires ) =
446 rearrange( [ 'NAME', [qw(VALUE VALUES)], 'PATH', 'SECURE', 'EXPIRES' ],
447 @p );
448 unless ( defined $value ) {
449 return keys %{ $this->{cookies} } unless $name;
450 return () unless $this->{cookies}{$name};
451 return $this->{cookies}{$name}->value if defined $name && $name ne '';
452 }
453 return unless defined $name && $name ne '';
454 return new CGI::Cookie(
455 -name => $name,
456 -value => $value,
457 -path => $path || '/',
458 -secure => $secure || $this->secure,
459 -expires => $expires || abs( $Foswiki::cfg{Sessions}{ExpireAfter} )
460 );
461}
462
463=begin TML
464
465ObjectMethod cookies( \%cookies ) -> $hashref
466
467Gets/Sets cookies hashref. Keys are cookie names
468and values CGI::Cookie objects.
469
470=cut
471
472sub cookies {
473 return @_ == 1 ? $_[0]->{cookies} : ( $_[0]->{cookies} = $_[1] );
474}
475
476=begin TML
477
478---++ ObjectMethod delete( @paramNames )
479
480Deletes parameters from request.
481
482=Delete()= alias provided for compatibility with CGI
483
484=cut
485
4861500ns*Delete = \&delete;
487
488
# spent 15µs within Foswiki::Request::delete which was called 2 times, avg 7µs/call: # once (9µs+0s) by Foswiki::Plugins::TablePlugin::Core::handler at line 1862 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (6µs+0s) by Foswiki::LoginManager::loadSession at line 491 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm
sub delete {
48921µs my $this = shift;
490213µs foreach my $p (@_) {
49142µs next unless exists $this->{param}{$p};
492 if ( my $upload = $this->{uploads}{ $this->param($p) } ) {
493 $upload->finish;
494 CORE::delete $this->{uploads}{ $this->param($p) };
495 }
496 CORE::delete $this->{param}{$p};
497 @{ $this->{param_list} } = grep { $_ ne $p } @{ $this->{param_list} };
498 }
499}
500
501=begin TML
502
503---++ ObjectMethod deleteAll()
504
505Deletes all parameter name and value(s).
506
507=delete_all()= alias provided for compatibility with CGI.
508
509=cut
510
5111400ns*delete_all = \&deleteAll;
512
513sub deleteAll {
514 my $this = shift;
515 $this->delete( $this->param() );
516}
517
518=begin TML
519
520---++ ObjectMethod header([-name => $name, -value => $value |
521 -name => $name, -values => [ $v1, $v2, ... ] |
522 $name, $v1, $v2, ... |
523 name, [ $v1, $v2, ... ]
524 ] ) -> @paramNames | @values | $firstValue
525
526Gets/Sets a header field:
527 * Called without parameters returns all header field names
528 * Called only with header field name or with -name => 'name'
529 * In list context returns all associated values (maybe empty list)
530 * In scalar context returns the first value (maybe undef)
531 * Called with name and list of values or with
532 -name => 'name', -value => 'value' or -name => 'name', -values => [ ... ]
533 sets header field value
534
535*Not compatible with CGI*, since CGI correspondent is a
536response write method. CGI scripts obtain headers from %ENV
537or =http= method. %ENV is not available and must be replaced
538by calls to this and other methods of this class. =http= is
539provided for compatibility, but is deprecated. Use this one
540instead.
541
542Calls to CGI =header= method must be replaced by calls to
543Foswiki::Response =header= method.
544
545=cut
546
547
# spent 135µs (80+55) within Foswiki::Request::header which was called 6 times, avg 22µs/call: # 4 times (43µs+32µs) by Foswiki::Request::url at line 266, avg 19µs/call # 2 times (37µs+23µs) by Foswiki::Request::userAgent at line 740, avg 30µs/call
sub header {
54869µs my ( $this, @p ) = @_;
549623µs655µs my ( $key, @value ) = rearrange( [ 'NAME', [qw(VALUE VALUES)] ], @p );
# spent 55µs making 6 calls to CGI::Util::rearrange, avg 9µs/call
550
55162µs return keys %{ $this->{headers} } unless $key;
55265µs $key =~ tr/_/-/;
55367µs $key = lc($key);
554
55562µs if ( defined $value[0] ) {
556 $this->{headers}{$key} =
557 ref $value[0] eq 'ARRAY' ? $value[0] : [@value];
558 }
55965µs if ( defined $this->{headers}{$key} ) {
560 return wantarray
561 ? @{ $this->{headers}{$key} }
562 : $this->{headers}{$key}->[0];
563 }
564 else {
565620µs return wantarray ? () : undef;
566 }
567}
568
569=begin TML
570
571---++ ObjectMethod save( $fh )
572
573Saves object state to filehandle. Object may be loaded latter
574passing $fh to new constructor or by calling load().
575
576=cut
577
578sub save {
579 my ( $this, $fh ) = @_;
580 local ( $\, $, ) = ( '', '' );
581 foreach my $name ( $this->param ) {
582 foreach my $value ( $this->param($name) ) {
583 $value = '' unless defined $value;
584 next if $name eq '' && $value eq ''; # Item12371
585 print $fh Foswiki::urlEncode($name), '=',
586 Foswiki::urlEncode($value), "\n";
587 }
588 }
589 print $fh "=\n";
590}
591
592=begin TML
593
594---++ ObjectMethod load( $fh )
595
596Loads object state from filehandle, probably created with
597a previous save().
598
599=cut
600
601sub load {
602 my ( $this, $file ) = @_;
603 my %param = ();
604 my @plist = ();
605 local $/ = "\n";
606 while (<$file>) {
607 chomp;
608 last if /^=$/;
609 my ( $key, $value ) =
610 map { defined $_ ? Foswiki::urlDecode($_) : $_ } split /=/;
611 if ( exists $param{$key} ) {
612 push @{ $param{$key} }, $value;
613 }
614 else {
615 push @plist, $key;
616 $param{$key} = [$value];
617 }
618 }
619 foreach my $key (@plist) {
620 $this->param( -name => $key, -value => $param{$key} );
621 }
622}
623
624=begin TML
625
626---++ ObjectMethod upload( $name ) -> $handle
627
628Called with file name parameter returns an open filehandle
629to uploaded file.
630
631=cut
632
633sub upload {
634 my ( $this, $name ) = @_;
635 my $upload = $this->{uploads}{ $this->param($name) };
636 return defined $upload ? $upload->handle : undef;
637}
638
639=begin TML
640
641---++ ObjectMethod uploadInfo( $fname ) -> $headers
642
643Returns a hashref to information about uploaded
644files as sent by browser.
645
646=cut
647
648sub uploadInfo {
649 return $_[0]->{uploads}{ $_[1] }->uploadInfo;
650}
651
652=begin TML
653
654---++ ObjectMethod tmpFileName( $fname ) -> $tmpFileName
655
656Returns the name of temporarly created file to store uploaded $fname.
657
658$fname may be obtained by calling =param()= with form field name.
659
660=cut
661
662sub tmpFileName {
663 my ( $this, $fname ) = @_;
664 return $this->{uploads}{$fname}
665 ? $this->{uploads}{$fname}->tmpFileName
666 : undef;
667}
668
669=begin TML
670
671---++ ObjectMethod uploads( [ \%uploads ] ) -> $hashref
672
673Gets/Sets request uploads field. Keys are uploaded file names,
674as sent by browser, and values are Foswiki::Request::Upload objects.
675
676=cut
677
678sub uploads {
679 return @_ == 1 ? $_[0]->{uploads} : ( $_[0]->{uploads} = $_[1] );
680}
681
682# ======== possible accessors =======
683# auth_type
684# content_length
685# content_type
686
687=begin TML
688
689---++ ObjectMethod http( [$header] ) -> $value DEPRECATED
690
691Called without parameters returns a list of all available header filed names.
692
693Given a field name returns value associated.
694
695http('HTTP_USER_AGENT'); http('User-Agent') and http('User_Agent')
696are equivalent.
697
698Please, use =header()= instead. Present only for compatibility with CGI.
699
700=cut
701
702sub http {
703 my ( $this, $p ) = @_;
704 if ( defined $p ) {
705 $p =~ s/^https?[_-]//i;
706 return $this->header($p);
707 }
708 return $this->header();
709}
710
711=begin TML
712
713---++ ObjectMethod https( [$name] ) -> $value || $secure DEPRECATED
714
715Similar to =http()= method above. Called with no parameters returns
716secure flag.
717
718Please, use =header()= and =secure()= instead.
719Present only for compatibility with CGI.
720
721=cut
722
723sub https {
724 my ( $this, $p ) = @_;
725 return !defined $p || $p =~ /^https$/i ? $this->secure : $this->http($p);
726}
727
728=begin TML
729
730---++ ObjectMethod userAgent() -> $userAgent;
731
732Convenience method to get User-Agent string.
733
734=user_agent()= alias provided for compatibility with CGI.
735
736=cut
737
7381400ns*user_agent = \&userAgent;
739
740215µs259µs
# spent 75µs (16+59) within Foswiki::Request::userAgent which was called 2 times, avg 38µs/call: # once (9µs+32µs) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 46 of /var/www/foswiki11/lib/Foswiki/Plugins/TinyMCEPlugin.pm # once (7µs+28µs) by Foswiki::logEvent at line 2254 of /var/www/foswiki11/lib/Foswiki.pm
sub userAgent { shift->header('User-Agent') }
# spent 59µs making 2 calls to Foswiki::Request::header, avg 30µs/call
741
742=begin TML
743
744---++ ObjectMethod referer()
745
746Convenience method to get Referer uri.
747
748=cut
749
750sub referer { shift->header('Referer') }
751
75218µs1;
753__END__