Filename | /usr/share/perl5/HTTP/Status.pm |
Statements | Executed 282 statements in 2.97ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
166 | 1 | 1 | 77µs | 77µs | CORE:match (opcode) | HTTP::Status::
1 | 1 | 1 | 17µs | 21µs | BEGIN@3 | HTTP::Status::
1 | 1 | 1 | 12µs | 109µs | BEGIN@6 | HTTP::Status::
0 | 0 | 0 | 0s | 0s | is_client_error | HTTP::Status::
0 | 0 | 0 | 0s | 0s | is_error | HTTP::Status::
0 | 0 | 0 | 0s | 0s | is_info | HTTP::Status::
0 | 0 | 0 | 0s | 0s | is_redirect | HTTP::Status::
0 | 0 | 0 | 0s | 0s | is_server_error | HTTP::Status::
0 | 0 | 0 | 0s | 0s | is_success | HTTP::Status::
0 | 0 | 0 | 0s | 0s | status_message | HTTP::Status::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package HTTP::Status; | ||||
2 | |||||
3 | 3 | 42µs | 2 | 25µs | # spent 21µs (17+4) within HTTP::Status::BEGIN@3 which was called:
# once (17µs+4µs) by LWP::Simple::BEGIN@14 at line 3 # spent 21µs making 1 call to HTTP::Status::BEGIN@3
# spent 4µs making 1 call to strict::import |
4 | 1 | 68µs | require 5.002; # because we use prototypes | ||
5 | |||||
6 | 3 | 571µs | 2 | 207µs | # spent 109µs (12+97) within HTTP::Status::BEGIN@6 which was called:
# once (12µs+97µs) by LWP::Simple::BEGIN@14 at line 6 # spent 109µs making 1 call to HTTP::Status::BEGIN@6
# spent 98µs making 1 call to vars::import |
7 | |||||
8 | 1 | 1µs | require Exporter; | ||
9 | 1 | 18µs | @ISA = qw(Exporter); | ||
10 | 1 | 2µs | @EXPORT = qw(is_info is_success is_redirect is_error status_message); | ||
11 | 1 | 800ns | @EXPORT_OK = qw(is_client_error is_server_error); | ||
12 | 1 | 400ns | $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 | |||||
19 | 1 | 44µs | my %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 | |||||
74 | 1 | 600ns | my $mnemonicCode = ''; | ||
75 | 1 | 500ns | my ($code, $message); | ||
76 | 1 | 5µs | while (($code, $message) = each %StatusCode) { | ||
77 | # create mnemonic subroutines | ||||
78 | 260 | 208µs | $message =~ tr/a-z \-/A-Z__/; | ||
79 | $mnemonicCode .= "sub HTTP_$message () { $code }\n"; | ||||
80 | $mnemonicCode .= "*RC_$message = \\&HTTP_$message;\n"; # legacy | ||||
81 | $mnemonicCode .= "push(\@EXPORT_OK, 'HTTP_$message');\n"; | ||||
82 | $mnemonicCode .= "push(\@EXPORT, 'RC_$message');\n"; | ||||
83 | } | ||||
84 | 1 | 1.66ms | eval $mnemonicCode; # only one eval for speed # spent 163µs executing statements in string eval | ||
85 | 1 | 500ns | die if $@; | ||
86 | |||||
87 | # backwards compatibility | ||||
88 | 1 | 900ns | *RC_MOVED_TEMPORARILY = \&RC_FOUND; # 302 was renamed in the standard | ||
89 | 1 | 900ns | push(@EXPORT, "RC_MOVED_TEMPORARILY"); | ||
90 | |||||
91 | 1 | 319µs | 166 | 77µs | %EXPORT_TAGS = ( # spent 77µs making 166 calls to HTTP::Status::CORE:match, avg 466ns/call |
92 | constants => [grep /^HTTP_/, @EXPORT_OK], | ||||
93 | is => [grep /^is_/, @EXPORT, @EXPORT_OK], | ||||
94 | ); | ||||
95 | |||||
96 | |||||
97 | sub status_message ($) { $StatusCode{$_[0]}; } | ||||
98 | |||||
99 | sub is_info ($) { $_[0] >= 100 && $_[0] < 200; } | ||||
100 | sub is_success ($) { $_[0] >= 200 && $_[0] < 300; } | ||||
101 | sub is_redirect ($) { $_[0] >= 300 && $_[0] < 400; } | ||||
102 | sub is_error ($) { $_[0] >= 400 && $_[0] < 600; } | ||||
103 | sub is_client_error ($) { $_[0] >= 400 && $_[0] < 500; } | ||||
104 | sub is_server_error ($) { $_[0] >= 500 && $_[0] < 600; } | ||||
105 | |||||
106 | 1 | 32µs | 1; | ||
107 | |||||
108 | |||||
109 | __END__ | ||||
# spent 77µs within HTTP::Status::CORE:match which was called 166 times, avg 466ns/call:
# 166 times (77µs+0s) by LWP::Simple::BEGIN@14 at line 91, avg 466ns/call |