| File | /project/perl/lib/HTTP/Status.pm |
| Statements Executed | 1081 |
| Statement Execution Time | 19.9ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 461 | 1 | 1 | 7.27ms | 7.27ms | HTTP::Status::is_success |
| 461 | 1 | 1 | 6.74ms | 6.74ms | HTTP::Status::status_message |
| 461 | 1 | 2 | 3.17ms | 3.17ms | HTTP::Status::RC_MOVED_PERMANENTLY (xsub) |
| 461 | 1 | 2 | 2.79ms | 2.79ms | HTTP::Status::RC_FOUND (xsub) |
| 461 | 1 | 2 | 2.75ms | 2.75ms | HTTP::Status::RC_PROXY_AUTHENTICATION_REQUIRED (xsub) |
| 461 | 1 | 2 | 2.72ms | 2.72ms | HTTP::Status::RC_SEE_OTHER (xsub) |
| 461 | 1 | 2 | 2.66ms | 2.66ms | HTTP::Status::RC_TEMPORARY_REDIRECT (xsub) |
| 461 | 1 | 2 | 2.64ms | 2.64ms | HTTP::Status::RC_UNAUTHORIZED (xsub) |
| 1 | 1 | 2 | 21µs | 21µs | HTTP::Status::CORE:match (opcode) |
| 0 | 0 | 0 | 0s | 0s | HTTP::Status::BEGIN |
| 0 | 0 | 0 | 0s | 0s | HTTP::Status::is_client_error |
| 0 | 0 | 0 | 0s | 0s | HTTP::Status::is_error |
| 0 | 0 | 0 | 0s | 0s | HTTP::Status::is_info |
| 0 | 0 | 0 | 0s | 0s | HTTP::Status::is_redirect |
| 0 | 0 | 0 | 0s | 0s | HTTP::Status::is_server_error |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package HTTP::Status; | ||||
| 2 | |||||
| 3 | # $Id: Status.pm,v 1.28 2003/10/23 18:56:01 uid39246 Exp $ | ||||
| 4 | |||||
| 5 | 3 | 117µs | 1 | 26µs | use strict; # spent 26µs making 1 call to strict::import |
| 6 | 1 | 5µs | require 5.002; # becase we use prototypes | ||
| 7 | |||||
| 8 | 3 | 1.08ms | 1 | 397µs | use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); # spent 397µs making 1 call to vars::import |
| 9 | |||||
| 10 | 1 | 26µs | require Exporter; | ||
| 11 | 1 | 11µs | @ISA = qw(Exporter); | ||
| 12 | 1 | 9µs | @EXPORT = qw(is_info is_success is_redirect is_error status_message); | ||
| 13 | 1 | 7µs | @EXPORT_OK = qw(is_client_error is_server_error); | ||
| 14 | 1 | 60µs | 1 | 21µs | $VERSION = sprintf("%d.%02d", q$Revision: 1.28 $ =~ /(\d+)\.(\d+)/); # spent 21µs making 1 call to HTTP::Status::CORE:match |
| 15 | |||||
| 16 | # Note also addition of mnemonics to @EXPORT below | ||||
| 17 | |||||
| 18 | 1 | 79µs | my %StatusCode = ( | ||
| 19 | 100 => 'Continue', | ||||
| 20 | 101 => 'Switching Protocols', | ||||
| 21 | 102 => 'Processing', # WebDAV | ||||
| 22 | 200 => 'OK', | ||||
| 23 | 201 => 'Created', | ||||
| 24 | 202 => 'Accepted', | ||||
| 25 | 203 => 'Non-Authoritative Information', | ||||
| 26 | 204 => 'No Content', | ||||
| 27 | 205 => 'Reset Content', | ||||
| 28 | 206 => 'Partial Content', | ||||
| 29 | 207 => 'Multi-Status', # WebDAV | ||||
| 30 | 300 => 'Multiple Choices', | ||||
| 31 | 301 => 'Moved Permanently', | ||||
| 32 | 302 => 'Found', | ||||
| 33 | 303 => 'See Other', | ||||
| 34 | 304 => 'Not Modified', | ||||
| 35 | 305 => 'Use Proxy', | ||||
| 36 | 307 => 'Temporary Redirect', | ||||
| 37 | 400 => 'Bad Request', | ||||
| 38 | 401 => 'Unauthorized', | ||||
| 39 | 402 => 'Payment Required', | ||||
| 40 | 403 => 'Forbidden', | ||||
| 41 | 404 => 'Not Found', | ||||
| 42 | 405 => 'Method Not Allowed', | ||||
| 43 | 406 => 'Not Acceptable', | ||||
| 44 | 407 => 'Proxy Authentication Required', | ||||
| 45 | 408 => 'Request Timeout', | ||||
| 46 | 409 => 'Conflict', | ||||
| 47 | 410 => 'Gone', | ||||
| 48 | 411 => 'Length Required', | ||||
| 49 | 412 => 'Precondition Failed', | ||||
| 50 | 413 => 'Request Entity Too Large', | ||||
| 51 | 414 => 'Request-URI Too Large', | ||||
| 52 | 415 => 'Unsupported Media Type', | ||||
| 53 | 416 => 'Request Range Not Satisfiable', | ||||
| 54 | 417 => 'Expectation Failed', | ||||
| 55 | 422 => 'Unprocessable Entity', # WebDAV | ||||
| 56 | 423 => 'Locked', # WebDAV | ||||
| 57 | 424 => 'Failed Dependency', # WebDAV | ||||
| 58 | 500 => 'Internal Server Error', | ||||
| 59 | 501 => 'Not Implemented', | ||||
| 60 | 502 => 'Bad Gateway', | ||||
| 61 | 503 => 'Service Unavailable', | ||||
| 62 | 504 => 'Gateway Timeout', | ||||
| 63 | 505 => 'HTTP Version Not Supported', | ||||
| 64 | 507 => 'Insufficient Storage', # WebDAV | ||||
| 65 | ); | ||||
| 66 | |||||
| 67 | 1 | 5µs | my $mnemonicCode = ''; | ||
| 68 | 1 | 5µs | my ($code, $message); | ||
| 69 | 1 | 14µs | while (($code, $message) = each %StatusCode) { | ||
| 70 | # create mnemonic subroutines | ||||
| 71 | 138 | 1.02ms | $message =~ tr/a-z \-/A-Z__/; | ||
| 72 | $mnemonicCode .= "sub RC_$message () { $code }\t"; | ||||
| 73 | # make them exportable | ||||
| 74 | $mnemonicCode .= "push(\@EXPORT, 'RC_$message');\n"; | ||||
| 75 | } | ||||
| 76 | # warn $mnemonicCode; # for development | ||||
| 77 | 1 | 1.82ms | eval $mnemonicCode; # only one eval for speed | ||
| 78 | 1 | 5µs | die if $@; | ||
| 79 | |||||
| 80 | # backwards compatibility | ||||
| 81 | 1 | 11µs | *RC_MOVED_TEMPORARILY = \&RC_FOUND; # 302 was renamed in the standard | ||
| 82 | 1 | 7µs | push(@EXPORT, "RC_MOVED_TEMPORARILY"); | ||
| 83 | |||||
| 84 | |||||
| 85 | 461 | 7.22ms | # spent 6.74ms within HTTP::Status::status_message which was called 461 times, avg 15µs/call:
# 461 times (6.74ms+0s) by LWP::UserAgent::request at line 287 of LWP/UserAgent.pm, avg 15µs/call | ||
| 86 | |||||
| 87 | sub is_info ($) { $_[0] >= 100 && $_[0] < 200; } | ||||
| 88 | 461 | 8.39ms | # spent 7.27ms within HTTP::Status::is_success which was called 461 times, avg 16µs/call:
# 461 times (7.27ms+0s) by HTTP::Response::is_success at line 117 of HTTP/Response.pm, avg 16µs/call | ||
| 89 | sub is_redirect ($) { $_[0] >= 300 && $_[0] < 400; } | ||||
| 90 | sub is_error ($) { $_[0] >= 400 && $_[0] < 600; } | ||||
| 91 | sub is_client_error ($) { $_[0] >= 400 && $_[0] < 500; } | ||||
| 92 | sub is_server_error ($) { $_[0] >= 500 && $_[0] < 600; } | ||||
| 93 | |||||
| 94 | 1 | 56µs | 1; | ||
| 95 | |||||
| 96 | |||||
| 97 | __END__ | ||||
| 98 | |||||
| 99 | =head1 NAME | ||||
| 100 | |||||
| 101 | HTTP::Status - HTTP Status code processing | ||||
| 102 | |||||
| 103 | =head1 SYNOPSIS | ||||
| 104 | |||||
| 105 | use HTTP::Status; | ||||
| 106 | |||||
| 107 | if ($rc != RC_OK) { | ||||
| 108 | print status_message($rc), "\n"; | ||||
| 109 | } | ||||
| 110 | |||||
| 111 | if (is_success($rc)) { ... } | ||||
| 112 | if (is_error($rc)) { ... } | ||||
| 113 | if (is_redirect($rc)) { ... } | ||||
| 114 | |||||
| 115 | =head1 DESCRIPTION | ||||
| 116 | |||||
| 117 | I<HTTP::Status> is a library of routines for defining and | ||||
| 118 | classifying HTTP status codes for libwww-perl. Status codes are | ||||
| 119 | used to encode the overall outcome of a HTTP response message. Codes | ||||
| 120 | correspond to those defined in RFC 2616 and RFC 2518. | ||||
| 121 | |||||
| 122 | =head1 CONSTANTS | ||||
| 123 | |||||
| 124 | The following constant functions can be used as mnemonic status code | ||||
| 125 | names: | ||||
| 126 | |||||
| 127 | RC_CONTINUE (100) | ||||
| 128 | RC_SWITCHING_PROTOCOLS (101) | ||||
| 129 | RC_PROCESSING (102) | ||||
| 130 | |||||
| 131 | RC_OK (200) | ||||
| 132 | RC_CREATED (201) | ||||
| 133 | RC_ACCEPTED (202) | ||||
| 134 | RC_NON_AUTHORITATIVE_INFORMATION (203) | ||||
| 135 | RC_NO_CONTENT (204) | ||||
| 136 | RC_RESET_CONTENT (205) | ||||
| 137 | RC_PARTIAL_CONTENT (206) | ||||
| 138 | RC_MULTI_STATUS (207) | ||||
| 139 | |||||
| 140 | RC_MULTIPLE_CHOICES (300) | ||||
| 141 | RC_MOVED_PERMANENTLY (301) | ||||
| 142 | RC_FOUND (302) | ||||
| 143 | RC_SEE_OTHER (303) | ||||
| 144 | RC_NOT_MODIFIED (304) | ||||
| 145 | RC_USE_PROXY (305) | ||||
| 146 | RC_TEMPORARY_REDIRECT (307) | ||||
| 147 | |||||
| 148 | RC_BAD_REQUEST (400) | ||||
| 149 | RC_UNAUTHORIZED (401) | ||||
| 150 | RC_PAYMENT_REQUIRED (402) | ||||
| 151 | RC_FORBIDDEN (403) | ||||
| 152 | RC_NOT_FOUND (404) | ||||
| 153 | RC_METHOD_NOT_ALLOWED (405) | ||||
| 154 | RC_NOT_ACCEPTABLE (406) | ||||
| 155 | RC_PROXY_AUTHENTICATION_REQUIRED (407) | ||||
| 156 | RC_REQUEST_TIMEOUT (408) | ||||
| 157 | RC_CONFLICT (409) | ||||
| 158 | RC_GONE (410) | ||||
| 159 | RC_LENGTH_REQUIRED (411) | ||||
| 160 | RC_PRECONDITION_FAILED (412) | ||||
| 161 | RC_REQUEST_ENTITY_TOO_LARGE (413) | ||||
| 162 | RC_REQUEST_URI_TOO_LARGE (414) | ||||
| 163 | RC_UNSUPPORTED_MEDIA_TYPE (415) | ||||
| 164 | RC_REQUEST_RANGE_NOT_SATISFIABLE (416) | ||||
| 165 | RC_EXPECTATION_FAILED (417) | ||||
| 166 | RC_UNPROCESSABLE_ENTITY (422) | ||||
| 167 | RC_LOCKED (423) | ||||
| 168 | RC_FAILED_DEPENDENCY (424) | ||||
| 169 | |||||
| 170 | RC_INTERNAL_SERVER_ERROR (500) | ||||
| 171 | RC_NOT_IMPLEMENTED (501) | ||||
| 172 | RC_BAD_GATEWAY (502) | ||||
| 173 | RC_SERVICE_UNAVAILABLE (503) | ||||
| 174 | RC_GATEWAY_TIMEOUT (504) | ||||
| 175 | RC_HTTP_VERSION_NOT_SUPPORTED (505) | ||||
| 176 | RC_INSUFFICIENT_STORAGE (507) | ||||
| 177 | |||||
| 178 | =head1 FUNCTIONS | ||||
| 179 | |||||
| 180 | The following additional functions are provided. Most of them are | ||||
| 181 | exported by default. | ||||
| 182 | |||||
| 183 | =over 4 | ||||
| 184 | |||||
| 185 | =item status_message( $code ) | ||||
| 186 | |||||
| 187 | The status_message() function will translate status codes to human | ||||
| 188 | readable strings. The string is the same as found in the constant | ||||
| 189 | names above. If the $code is unknown, then C<undef> is returned. | ||||
| 190 | |||||
| 191 | =item is_info( $code ) | ||||
| 192 | |||||
| 193 | Return TRUE if C<$code> is an I<Informational> status code. This | ||||
| 194 | class of status code indicates a provisional response which can't have | ||||
| 195 | any content. | ||||
| 196 | |||||
| 197 | =item is_success( $code ) | ||||
| 198 | |||||
| 199 | Return TRUE if C<$code> is a I<Successful> status code. | ||||
| 200 | |||||
| 201 | =item is_redirect( $code ) | ||||
| 202 | |||||
| 203 | Return TRUE if C<$code> is a I<Redirection> status code. This class of | ||||
| 204 | status code indicates that further action needs to be taken by the | ||||
| 205 | user agent in order to fulfill the request. | ||||
| 206 | |||||
| 207 | =item is_error( $code ) | ||||
| 208 | |||||
| 209 | Return TRUE if C<$code> is an I<Error> status code. The function | ||||
| 210 | return TRUE for both client error or a server error status codes. | ||||
| 211 | |||||
| 212 | =item is_client_error( $code ) | ||||
| 213 | |||||
| 214 | Return TRUE if C<$code> is an I<Client Error> status code. This class | ||||
| 215 | of status code is intended for cases in which the client seems to have | ||||
| 216 | erred. | ||||
| 217 | |||||
| 218 | This function is B<not> exported by default. | ||||
| 219 | |||||
| 220 | =item is_server_error( $code ) | ||||
| 221 | |||||
| 222 | Return TRUE if C<$code> is an I<Server Error> status code. This class | ||||
| 223 | of status codes is intended for cases in which the server is aware | ||||
| 224 | that it has erred or is incapable of performing the request. | ||||
| 225 | |||||
| 226 | This function is B<not> exported by default. | ||||
| 227 | |||||
| 228 | =back | ||||
| 229 | |||||
| 230 | =head1 BUGS | ||||
| 231 | |||||
| 232 | Wished @EXPORT_OK had been used instead of @EXPORT in the beginning. | ||||
| 233 | Now too much is exported by default. | ||||
| 234 | |||||
# spent 21µs within HTTP::Status::CORE:match which was called
# once (21µs+0s) by HTTP::Response::BEGIN at line 14 of HTTP/Status.pm | |||||
# spent 2.79ms within HTTP::Status::RC_FOUND which was called 461 times, avg 6µs/call:
# 461 times (2.79ms+0s) by LWP::UserAgent::request at line 291 of LWP/UserAgent.pm, avg 6µs/call | |||||
# spent 3.17ms within HTTP::Status::RC_MOVED_PERMANENTLY which was called 461 times, avg 7µs/call:
# 461 times (3.17ms+0s) by LWP::UserAgent::request at line 291 of LWP/UserAgent.pm, avg 7µs/call | |||||
# spent 2.75ms within HTTP::Status::RC_PROXY_AUTHENTICATION_REQUIRED which was called 461 times, avg 6µs/call:
# 461 times (2.75ms+0s) by LWP::UserAgent::request at line 291 of LWP/UserAgent.pm, avg 6µs/call | |||||
# spent 2.72ms within HTTP::Status::RC_SEE_OTHER which was called 461 times, avg 6µs/call:
# 461 times (2.72ms+0s) by LWP::UserAgent::request at line 291 of LWP/UserAgent.pm, avg 6µs/call | |||||
# spent 2.66ms within HTTP::Status::RC_TEMPORARY_REDIRECT which was called 461 times, avg 6µs/call:
# 461 times (2.66ms+0s) by LWP::UserAgent::request at line 291 of LWP/UserAgent.pm, avg 6µs/call | |||||
# spent 2.64ms within HTTP::Status::RC_UNAUTHORIZED which was called 461 times, avg 6µs/call:
# 461 times (2.64ms+0s) by LWP::UserAgent::request at line 291 of LWP/UserAgent.pm, avg 6µs/call |