← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 01.HTTP.t
  Run on Tue May 4 15:25:55 2010
Reported on Tue May 4 15:26:16 2010

File /usr/local/lib/perl5/site_perl/5.10.1/HTTP/Status.pm
Statements Executed 285
Statement Execution Time 2.31ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1661226µs26µsHTTP::Status::::CORE:matchHTTP::Status::CORE:match (opcode)
11115µs18µsHTTP::Status::::BEGIN@3HTTP::Status::BEGIN@3
31114µs14µsHTTP::Status::::is_successHTTP::Status::is_success
3128µs8µsHTTP::Status::::HTTP_MOVED_PERMANENTLYHTTP::Status::HTTP_MOVED_PERMANENTLY (xsub)
1117µs83µsHTTP::Status::::BEGIN@6HTTP::Status::BEGIN@6
3125µs5µsHTTP::Status::::HTTP_PROXY_AUTHENTICATION_REQUIREDHTTP::Status::HTTP_PROXY_AUTHENTICATION_REQUIRED (xsub)
3125µs5µsHTTP::Status::::HTTP_FOUNDHTTP::Status::HTTP_FOUND (xsub)
3124µs4µsHTTP::Status::::HTTP_UNAUTHORIZEDHTTP::Status::HTTP_UNAUTHORIZED (xsub)
3124µs4µsHTTP::Status::::HTTP_TEMPORARY_REDIRECTHTTP::Status::HTTP_TEMPORARY_REDIRECT (xsub)
3124µs4µsHTTP::Status::::HTTP_SEE_OTHERHTTP::Status::HTTP_SEE_OTHER (xsub)
0000s0sHTTP::Status::::is_client_errorHTTP::Status::is_client_error
0000s0sHTTP::Status::::is_errorHTTP::Status::is_error
0000s0sHTTP::Status::::is_infoHTTP::Status::is_info
0000s0sHTTP::Status::::is_redirectHTTP::Status::is_redirect
0000s0sHTTP::Status::::is_server_errorHTTP::Status::is_server_error
0000s0sHTTP::Status::::status_messageHTTP::Status::status_message
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package HTTP::Status;
2
3330µs220µs
# spent 18µs (15+3) within HTTP::Status::BEGIN@3 which was called # once (15µs+3µs) by HTTP::Response::BEGIN@8 at line 3
use strict;
# spent 18µs making 1 call to HTTP::Status::BEGIN@3 # spent 3µs making 1 call to strict::import
4148µsrequire 5.002; # because we use prototypes
5
63390µs2158µs
# spent 83µs (7+76) within HTTP::Status::BEGIN@6 which was called # once (7µs+76µs) by HTTP::Response::BEGIN@8 at line 6
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
# spent 83µs making 1 call to HTTP::Status::BEGIN@6 # spent 75µs making 1 call to vars::import
7
81300nsrequire Exporter;
917µs@ISA = qw(Exporter);
1011µs@EXPORT = qw(is_info is_success is_redirect is_error status_message);
111400ns@EXPORT_OK = qw(is_client_error is_server_error);
121300ns$VERSION = "5.817";
13
14# Note also addition of mnemonics to @EXPORT below
15
16# Unmarked codes are from RFC 2616
17# See also: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
18
19137µsmy %StatusCode = (
20 100 => 'Continue',
21 101 => 'Switching Protocols',
22 102 => 'Processing', # RFC 2518 (WebDAV)
23 200 => 'OK',
24 201 => 'Created',
25 202 => 'Accepted',
26 203 => 'Non-Authoritative Information',
27 204 => 'No Content',
28 205 => 'Reset Content',
29 206 => 'Partial Content',
30 207 => 'Multi-Status', # RFC 2518 (WebDAV)
31 300 => 'Multiple Choices',
32 301 => 'Moved Permanently',
33 302 => 'Found',
34 303 => 'See Other',
35 304 => 'Not Modified',
36 305 => 'Use Proxy',
37 307 => 'Temporary Redirect',
38 400 => 'Bad Request',
39 401 => 'Unauthorized',
40 402 => 'Payment Required',
41 403 => 'Forbidden',
42 404 => 'Not Found',
43 405 => 'Method Not Allowed',
44 406 => 'Not Acceptable',
45 407 => 'Proxy Authentication Required',
46 408 => 'Request Timeout',
47 409 => 'Conflict',
48 410 => 'Gone',
49 411 => 'Length Required',
50 412 => 'Precondition Failed',
51 413 => 'Request Entity Too Large',
52 414 => 'Request-URI Too Large',
53 415 => 'Unsupported Media Type',
54 416 => 'Request Range Not Satisfiable',
55 417 => 'Expectation Failed',
56 422 => 'Unprocessable Entity', # RFC 2518 (WebDAV)
57 423 => 'Locked', # RFC 2518 (WebDAV)
58 424 => 'Failed Dependency', # RFC 2518 (WebDAV)
59 425 => 'No code', # WebDAV Advanced Collections
60 426 => 'Upgrade Required', # RFC 2817
61 449 => 'Retry with', # unofficial Microsoft
62 500 => 'Internal Server Error',
63 501 => 'Not Implemented',
64 502 => 'Bad Gateway',
65 503 => 'Service Unavailable',
66 504 => 'Gateway Timeout',
67 505 => 'HTTP Version Not Supported',
68 506 => 'Variant Also Negotiates', # RFC 2295
69 507 => 'Insufficient Storage', # RFC 2518 (WebDAV)
70 509 => 'Bandwidth Limit Exceeded', # unofficial
71 510 => 'Not Extended', # RFC 2774
72);
73
741300nsmy $mnemonicCode = '';
751200nsmy ($code, $message);
7616µswhile (($code, $message) = each %StatusCode) {
77 # create mnemonic subroutines
785211µs $message =~ tr/a-z \-/A-Z__/;
795226µs $mnemonicCode .= "sub HTTP_$message () { $code }\n";
805225µs $mnemonicCode .= "*RC_$message = \\&HTTP_$message;\n"; # legacy
815216µs $mnemonicCode .= "push(\@EXPORT_OK, 'HTTP_$message');\n";
825236µs $mnemonicCode .= "push(\@EXPORT, 'RC_$message');\n";
83}
8411.40mseval $mnemonicCode; # only one eval for speed
851100nsdie if $@;
86
87# backwards compatibility
881700ns*RC_MOVED_TEMPORARILY = \&RC_FOUND; # 302 was renamed in the standard
891400nspush(@EXPORT, "RC_MOVED_TEMPORARILY");
90
911203µs16626µs%EXPORT_TAGS = (
# spent 26µs making 166 calls to HTTP::Status::CORE:match, avg 157ns/call
92 constants => [grep /^HTTP_/, @EXPORT_OK],
93 is => [grep /^is_/, @EXPORT, @EXPORT_OK],
94);
95
96
97sub status_message ($) { $StatusCode{$_[0]}; }
98
99sub is_info ($) { $_[0] >= 100 && $_[0] < 200; }
100317µs
# spent 14µs within HTTP::Status::is_success which was called 3 times, avg 5µs/call: # 3 times (14µs+0s) by HTTP::Response::is_success at line 215 of HTTP/Response.pm, avg 5µs/call
sub is_success ($) { $_[0] >= 200 && $_[0] < 300; }
101sub is_redirect ($) { $_[0] >= 300 && $_[0] < 400; }
102sub is_error ($) { $_[0] >= 400 && $_[0] < 600; }
103sub is_client_error ($) { $_[0] >= 400 && $_[0] < 500; }
104sub is_server_error ($) { $_[0] >= 500 && $_[0] < 600; }
105
106150µs1;
107
108
109__END__
110
111=head1 NAME
112
113HTTP::Status - HTTP Status code processing
114
115=head1 SYNOPSIS
116
117 use HTTP::Status qw(:constants :is status_message);
118
119 if ($rc != HTTP_OK) {
120 print status_message($rc), "\n";
121 }
122
123 if (is_success($rc)) { ... }
124 if (is_error($rc)) { ... }
125 if (is_redirect($rc)) { ... }
126
127=head1 DESCRIPTION
128
129I<HTTP::Status> is a library of routines for defining and
130classifying HTTP status codes for libwww-perl. Status codes are
131used to encode the overall outcome of a HTTP response message. Codes
132correspond to those defined in RFC 2616 and RFC 2518.
133
134=head1 CONSTANTS
135
136The following constant functions can be used as mnemonic status code
137names. None of these are exported by default. Use the C<:constants>
138tag to import them all.
139
140 HTTP_CONTINUE (100)
141 HTTP_SWITCHING_PROTOCOLS (101)
142 HTTP_PROCESSING (102)
143
144 HTTP_OK (200)
145 HTTP_CREATED (201)
146 HTTP_ACCEPTED (202)
147 HTTP_NON_AUTHORITATIVE_INFORMATION (203)
148 HTTP_NO_CONTENT (204)
149 HTTP_RESET_CONTENT (205)
150 HTTP_PARTIAL_CONTENT (206)
151 HTTP_MULTI_STATUS (207)
152
153 HTTP_MULTIPLE_CHOICES (300)
154 HTTP_MOVED_PERMANENTLY (301)
155 HTTP_FOUND (302)
156 HTTP_SEE_OTHER (303)
157 HTTP_NOT_MODIFIED (304)
158 HTTP_USE_PROXY (305)
159 HTTP_TEMPORARY_REDIRECT (307)
160
161 HTTP_BAD_REQUEST (400)
162 HTTP_UNAUTHORIZED (401)
163 HTTP_PAYMENT_REQUIRED (402)
164 HTTP_FORBIDDEN (403)
165 HTTP_NOT_FOUND (404)
166 HTTP_METHOD_NOT_ALLOWED (405)
167 HTTP_NOT_ACCEPTABLE (406)
168 HTTP_PROXY_AUTHENTICATION_REQUIRED (407)
169 HTTP_REQUEST_TIMEOUT (408)
170 HTTP_CONFLICT (409)
171 HTTP_GONE (410)
172 HTTP_LENGTH_REQUIRED (411)
173 HTTP_PRECONDITION_FAILED (412)
174 HTTP_REQUEST_ENTITY_TOO_LARGE (413)
175 HTTP_REQUEST_URI_TOO_LARGE (414)
176 HTTP_UNSUPPORTED_MEDIA_TYPE (415)
177 HTTP_REQUEST_RANGE_NOT_SATISFIABLE (416)
178 HTTP_EXPECTATION_FAILED (417)
179 HTTP_UNPROCESSABLE_ENTITY (422)
180 HTTP_LOCKED (423)
181 HTTP_FAILED_DEPENDENCY (424)
182 HTTP_NO_CODE (425)
183 HTTP_UPGRADE_REQUIRED (426)
184 HTTP_RETRY_WITH (449)
185
186 HTTP_INTERNAL_SERVER_ERROR (500)
187 HTTP_NOT_IMPLEMENTED (501)
188 HTTP_BAD_GATEWAY (502)
189 HTTP_SERVICE_UNAVAILABLE (503)
190 HTTP_GATEWAY_TIMEOUT (504)
191 HTTP_HTTP_VERSION_NOT_SUPPORTED (505)
192 HTTP_VARIANT_ALSO_NEGOTIATES (506)
193 HTTP_INSUFFICIENT_STORAGE (507)
194 HTTP_BANDWIDTH_LIMIT_EXCEEDED (509)
195 HTTP_NOT_EXTENDED (510)
196
197=head1 FUNCTIONS
198
199The following additional functions are provided. Most of them are
200exported by default. The C<:is> import tag can be used to import all
201the classification functions.
202
203=over 4
204
205=item status_message( $code )
206
207The status_message() function will translate status codes to human
208readable strings. The string is the same as found in the constant
209names above. If the $code is unknown, then C<undef> is returned.
210
211=item is_info( $code )
212
213Return TRUE if C<$code> is an I<Informational> status code (1xx). This
214class of status code indicates a provisional response which can't have
215any content.
216
217=item is_success( $code )
218
219Return TRUE if C<$code> is a I<Successful> status code (2xx).
220
221=item is_redirect( $code )
222
223Return TRUE if C<$code> is a I<Redirection> status code (3xx). This class of
224status code indicates that further action needs to be taken by the
225user agent in order to fulfill the request.
226
227=item is_error( $code )
228
229Return TRUE if C<$code> is an I<Error> status code (4xx or 5xx). The function
230return TRUE for both client error or a server error status codes.
231
232=item is_client_error( $code )
233
234Return TRUE if C<$code> is an I<Client Error> status code (4xx). This class
235of status code is intended for cases in which the client seems to have
236erred.
237
238This function is B<not> exported by default.
239
240=item is_server_error( $code )
241
242Return TRUE if C<$code> is an I<Server Error> status code (5xx). This class
243of status codes is intended for cases in which the server is aware
244that it has erred or is incapable of performing the request.
245
246This function is B<not> exported by default.
247
248=back
249
250=head1 BUGS
251
252For legacy reasons all the C<HTTP_> constants are exported by default
253with the prefix C<RC_>. It's recommended to use explict imports and
254the C<:constants> tag instead of relying on this.
# spent 26µs within HTTP::Status::CORE:match which was called 166 times, avg 157ns/call: # 166 times (26µs+0s) by HTTP::Response::BEGIN@8 at line 91 of HTTP/Status.pm, avg 157ns/call
sub HTTP::Status::CORE:match; # xsub
# spent 5µs within HTTP::Status::HTTP_FOUND which was called 3 times, avg 2µs/call: # 3 times (5µs+0s) by LWP::UserAgent::request at line 276 of LWP/UserAgent.pm, avg 2µs/call
sub HTTP::Status::HTTP_FOUND; # xsub
# spent 8µs within HTTP::Status::HTTP_MOVED_PERMANENTLY which was called 3 times, avg 3µs/call: # 3 times (8µs+0s) by LWP::UserAgent::request at line 276 of LWP/UserAgent.pm, avg 3µs/call
sub HTTP::Status::HTTP_MOVED_PERMANENTLY; # xsub
# spent 5µs within HTTP::Status::HTTP_PROXY_AUTHENTICATION_REQUIRED which was called 3 times, avg 2µs/call: # 3 times (5µs+0s) by LWP::UserAgent::request at line 276 of LWP/UserAgent.pm, avg 2µs/call
sub HTTP::Status::HTTP_PROXY_AUTHENTICATION_REQUIRED; # xsub
# spent 4µs within HTTP::Status::HTTP_SEE_OTHER which was called 3 times, avg 1µs/call: # 3 times (4µs+0s) by LWP::UserAgent::request at line 276 of LWP/UserAgent.pm, avg 1µs/call
sub HTTP::Status::HTTP_SEE_OTHER; # xsub
# spent 4µs within HTTP::Status::HTTP_TEMPORARY_REDIRECT which was called 3 times, avg 1µs/call: # 3 times (4µs+0s) by LWP::UserAgent::request at line 276 of LWP/UserAgent.pm, avg 1µs/call
sub HTTP::Status::HTTP_TEMPORARY_REDIRECT; # xsub
# spent 4µs within HTTP::Status::HTTP_UNAUTHORIZED which was called 3 times, avg 2µs/call: # 3 times (4µs+0s) by LWP::UserAgent::request at line 276 of LWP/UserAgent.pm, avg 2µs/call
sub HTTP::Status::HTTP_UNAUTHORIZED; # xsub