Filename | /usr/share/perl5/HTTP/Status.pm |
Statements | Executed 368 statements in 2.03ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
184 | 1 | 1 | 21µs | 21µs | CORE:match (opcode) | HTTP::Status::
58 | 1 | 1 | 15µs | 15µs | CORE:subst (opcode) | HTTP::Status::
1 | 1 | 1 | 11µs | 21µs | BEGIN@3 | HTTP::Status::
1 | 1 | 1 | 7µs | 63µ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 | 2 | 30µs | 2 | 31µs | # spent 21µs (11+10) within HTTP::Status::BEGIN@3 which was called:
# once (11µs+10µs) by HTTP::Response::BEGIN@8 at line 3 # spent 21µs making 1 call to HTTP::Status::BEGIN@3
# spent 10µs making 1 call to strict::import |
4 | 1 | 13µs | require 5.002; # because we use prototypes | ||
5 | |||||
6 | 2 | 397µs | 2 | 118µs | # spent 63µs (7+55) within HTTP::Status::BEGIN@6 which was called:
# once (7µs+55µs) by HTTP::Response::BEGIN@8 at line 6 # spent 63µs making 1 call to HTTP::Status::BEGIN@6
# spent 55µs making 1 call to vars::import |
7 | |||||
8 | 1 | 600ns | require Exporter; | ||
9 | 1 | 6µs | @ISA = qw(Exporter); | ||
10 | 1 | 700ns | @EXPORT = qw(is_info is_success is_redirect is_error status_message); | ||
11 | 1 | 300ns | @EXPORT_OK = qw(is_client_error is_server_error); | ||
12 | 1 | 100ns | $VERSION = "6.03"; | ||
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 | 45µ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 | 208 => 'Already Reported', # RFC 5842 | ||||
32 | 300 => 'Multiple Choices', | ||||
33 | 301 => 'Moved Permanently', | ||||
34 | 302 => 'Found', | ||||
35 | 303 => 'See Other', | ||||
36 | 304 => 'Not Modified', | ||||
37 | 305 => 'Use Proxy', | ||||
38 | 307 => 'Temporary Redirect', | ||||
39 | 400 => 'Bad Request', | ||||
40 | 401 => 'Unauthorized', | ||||
41 | 402 => 'Payment Required', | ||||
42 | 403 => 'Forbidden', | ||||
43 | 404 => 'Not Found', | ||||
44 | 405 => 'Method Not Allowed', | ||||
45 | 406 => 'Not Acceptable', | ||||
46 | 407 => 'Proxy Authentication Required', | ||||
47 | 408 => 'Request Timeout', | ||||
48 | 409 => 'Conflict', | ||||
49 | 410 => 'Gone', | ||||
50 | 411 => 'Length Required', | ||||
51 | 412 => 'Precondition Failed', | ||||
52 | 413 => 'Request Entity Too Large', | ||||
53 | 414 => 'Request-URI Too Large', | ||||
54 | 415 => 'Unsupported Media Type', | ||||
55 | 416 => 'Request Range Not Satisfiable', | ||||
56 | 417 => 'Expectation Failed', | ||||
57 | 418 => 'I\'m a teapot', # RFC 2324 | ||||
58 | 422 => 'Unprocessable Entity', # RFC 2518 (WebDAV) | ||||
59 | 423 => 'Locked', # RFC 2518 (WebDAV) | ||||
60 | 424 => 'Failed Dependency', # RFC 2518 (WebDAV) | ||||
61 | 425 => 'No code', # WebDAV Advanced Collections | ||||
62 | 426 => 'Upgrade Required', # RFC 2817 | ||||
63 | 428 => 'Precondition Required', | ||||
64 | 429 => 'Too Many Requests', | ||||
65 | 431 => 'Request Header Fields Too Large', | ||||
66 | 449 => 'Retry with', # unofficial Microsoft | ||||
67 | 500 => 'Internal Server Error', | ||||
68 | 501 => 'Not Implemented', | ||||
69 | 502 => 'Bad Gateway', | ||||
70 | 503 => 'Service Unavailable', | ||||
71 | 504 => 'Gateway Timeout', | ||||
72 | 505 => 'HTTP Version Not Supported', | ||||
73 | 506 => 'Variant Also Negotiates', # RFC 2295 | ||||
74 | 507 => 'Insufficient Storage', # RFC 2518 (WebDAV) | ||||
75 | 509 => 'Bandwidth Limit Exceeded', # unofficial | ||||
76 | 510 => 'Not Extended', # RFC 2774 | ||||
77 | 511 => 'Network Authentication Required', | ||||
78 | ); | ||||
79 | |||||
80 | 1 | 200ns | my $mnemonicCode = ''; | ||
81 | 1 | 100ns | my ($code, $message); | ||
82 | 1 | 2µs | while (($code, $message) = each %StatusCode) { | ||
83 | # create mnemonic subroutines | ||||
84 | 58 | 67µs | 58 | 15µs | $message =~ s/I'm/I am/; # spent 15µs making 58 calls to HTTP::Status::CORE:subst, avg 253ns/call |
85 | 58 | 12µs | $message =~ tr/a-z \-/A-Z__/; | ||
86 | 58 | 20µs | $mnemonicCode .= "sub HTTP_$message () { $code }\n"; | ||
87 | 58 | 14µs | $mnemonicCode .= "*RC_$message = \\&HTTP_$message;\n"; # legacy | ||
88 | 58 | 11µs | $mnemonicCode .= "push(\@EXPORT_OK, 'HTTP_$message');\n"; | ||
89 | 58 | 39µs | $mnemonicCode .= "push(\@EXPORT, 'RC_$message');\n"; | ||
90 | } | ||||
91 | 1 | 1.20ms | eval $mnemonicCode; # only one eval for speed # spent 55µs executing statements in string eval | ||
92 | 1 | 200ns | die if $@; | ||
93 | |||||
94 | # backwards compatibility | ||||
95 | 1 | 600ns | *RC_MOVED_TEMPORARILY = \&RC_FOUND; # 302 was renamed in the standard | ||
96 | 1 | 400ns | push(@EXPORT, "RC_MOVED_TEMPORARILY"); | ||
97 | |||||
98 | 1 | 158µs | 184 | 21µs | %EXPORT_TAGS = ( # spent 21µs making 184 calls to HTTP::Status::CORE:match, avg 116ns/call |
99 | constants => [grep /^HTTP_/, @EXPORT_OK], | ||||
100 | is => [grep /^is_/, @EXPORT, @EXPORT_OK], | ||||
101 | ); | ||||
102 | |||||
103 | |||||
104 | sub status_message ($) { $StatusCode{$_[0]}; } | ||||
105 | |||||
106 | sub is_info ($) { $_[0] >= 100 && $_[0] < 200; } | ||||
107 | sub is_success ($) { $_[0] >= 200 && $_[0] < 300; } | ||||
108 | sub is_redirect ($) { $_[0] >= 300 && $_[0] < 400; } | ||||
109 | sub is_error ($) { $_[0] >= 400 && $_[0] < 600; } | ||||
110 | sub is_client_error ($) { $_[0] >= 400 && $_[0] < 500; } | ||||
111 | sub is_server_error ($) { $_[0] >= 500 && $_[0] < 600; } | ||||
112 | |||||
113 | 1 | 16µs | 1; | ||
114 | |||||
115 | |||||
116 | __END__ | ||||
# spent 21µs within HTTP::Status::CORE:match which was called 184 times, avg 116ns/call:
# 184 times (21µs+0s) by HTTP::Response::BEGIN@8 at line 98, avg 116ns/call | |||||
# spent 15µs within HTTP::Status::CORE:subst which was called 58 times, avg 253ns/call:
# 58 times (15µs+0s) by HTTP::Response::BEGIN@8 at line 84, avg 253ns/call |