Commit c9d59c6b035cfd6b1fc13f7996adae27e1b056f7

Rename the HTTP::Status constants to have HTTP_ prefix
MANIFEST
(1 / 0)
  
8585t/base/request.t Test additional HTTP::Request methods
8686t/base/response.t Test additional HTTP::Response methods
8787t/base/status.t Test HTTP::Status module
88t/base/status-old.t Test HTTP::Status module
8889t/base/ua.t Basic LWP::UserAgent tests
8990t/html/form.t Test HTML::Form module
9091t/html/form-param.t More HTML::Form tests.
lib/HTTP/Status.pm
(70 / 62)
  
33use strict;
44require 5.002; # because we use prototypes
55
6use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
6use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
77
88require Exporter;
99@ISA = qw(Exporter);
7676while (($code, $message) = each %StatusCode) {
7777 # create mnemonic subroutines
7878 $message =~ tr/a-z \-/A-Z__/;
79 $mnemonicCode .= "sub RC_$message () { $code }\t";
80 # make them exportable
79 $mnemonicCode .= "sub HTTP_$message () { $code }\n";
80 $mnemonicCode .= "*RC_$message = \\&HTTP_$message;\n"; # legacy
81 $mnemonicCode .= "push(\@EXPORT_OK, 'HTTP_$message');\n";
8182 $mnemonicCode .= "push(\@EXPORT, 'RC_$message');\n";
8283}
83# warn $mnemonicCode; # for development
8484eval $mnemonicCode; # only one eval for speed
8585die if $@;
8686
8888*RC_MOVED_TEMPORARILY = \&RC_FOUND; # 302 was renamed in the standard
8989push(@EXPORT, "RC_MOVED_TEMPORARILY");
9090
91%EXPORT_TAGS = (
92 constants => [grep /^HTTP_/, @EXPORT_OK],
93 is => [grep /^is_/, @EXPORT, @EXPORT_OK],
94);
9195
96
9297sub status_message ($) { $StatusCode{$_[0]}; }
9398
9499sub is_info ($) { $_[0] >= 100 && $_[0] < 200; }
114114
115115=head1 SYNOPSIS
116116
117 use HTTP::Status;
117 use HTTP::Status qw(:constants :is status_message);
118118
119 if ($rc != RC_OK) {
119 if ($rc != HTTP_OK) {
120120 print status_message($rc), "\n";
121121 }
122122
134134=head1 CONSTANTS
135135
136136The following constant functions can be used as mnemonic status code
137names:
137names. None of these are exported by default. Use the C<:constants>
138tag to import them all.
138139
139 RC_CONTINUE (100)
140 RC_SWITCHING_PROTOCOLS (101)
141 RC_PROCESSING (102)
140 HTTP_CONTINUE (100)
141 HTTP_SWITCHING_PROTOCOLS (101)
142 HTTP_PROCESSING (102)
142143
143 RC_OK (200)
144 RC_CREATED (201)
145 RC_ACCEPTED (202)
146 RC_NON_AUTHORITATIVE_INFORMATION (203)
147 RC_NO_CONTENT (204)
148 RC_RESET_CONTENT (205)
149 RC_PARTIAL_CONTENT (206)
150 RC_MULTI_STATUS (207)
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)
151152
152 RC_MULTIPLE_CHOICES (300)
153 RC_MOVED_PERMANENTLY (301)
154 RC_FOUND (302)
155 RC_SEE_OTHER (303)
156 RC_NOT_MODIFIED (304)
157 RC_USE_PROXY (305)
158 RC_TEMPORARY_REDIRECT (307)
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)
159160
160 RC_BAD_REQUEST (400)
161 RC_UNAUTHORIZED (401)
162 RC_PAYMENT_REQUIRED (402)
163 RC_FORBIDDEN (403)
164 RC_NOT_FOUND (404)
165 RC_METHOD_NOT_ALLOWED (405)
166 RC_NOT_ACCEPTABLE (406)
167 RC_PROXY_AUTHENTICATION_REQUIRED (407)
168 RC_REQUEST_TIMEOUT (408)
169 RC_CONFLICT (409)
170 RC_GONE (410)
171 RC_LENGTH_REQUIRED (411)
172 RC_PRECONDITION_FAILED (412)
173 RC_REQUEST_ENTITY_TOO_LARGE (413)
174 RC_REQUEST_URI_TOO_LARGE (414)
175 RC_UNSUPPORTED_MEDIA_TYPE (415)
176 RC_REQUEST_RANGE_NOT_SATISFIABLE (416)
177 RC_EXPECTATION_FAILED (417)
178 RC_UNPROCESSABLE_ENTITY (422)
179 RC_LOCKED (423)
180 RC_FAILED_DEPENDENCY (424)
181 RC_NO_CODE (425)
182 RC_UPGRADE_REQUIRED (426)
183 RC_RETRY_WITH (449)
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)
184185
185 RC_INTERNAL_SERVER_ERROR (500)
186 RC_NOT_IMPLEMENTED (501)
187 RC_BAD_GATEWAY (502)
188 RC_SERVICE_UNAVAILABLE (503)
189 RC_GATEWAY_TIMEOUT (504)
190 RC_HTTP_VERSION_NOT_SUPPORTED (505)
191 RC_VARIANT_ALSO_NEGOTIATES (506)
192 RC_INSUFFICIENT_STORAGE (507)
193 RC_BANDWIDTH_LIMIT_EXCEEDED (509)
194 RC_NOT_EXTENDED (510)
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)
195196
196197=head1 FUNCTIONS
197198
198199The following additional functions are provided. Most of them are
199exported by default.
200exported by default. The C<:is> import tag can be used to import all
201the classification functions.
200202
201203=over 4
202204
249249
250250=head1 BUGS
251251
252Wished @EXPORT_OK had been used instead of @EXPORT in the beginning.
253Now too much is exported by default.
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.
t/base/status-old.t
(18 / 0)
  
1#!perl -w
2
3use Test;
4plan tests => 8;
5
6use HTTP::Status;
7
8ok(RC_OK, 200);
9
10ok(is_info(RC_CONTINUE));
11ok(is_success(RC_ACCEPTED));
12ok(is_error(RC_BAD_REQUEST));
13ok(is_redirect(RC_MOVED_PERMANENTLY));
14
15ok(!is_success(RC_NOT_FOUND));
16
17ok(status_message(0), undef);
18ok(status_message(200), "OK");
t/base/status.t
(7 / 7)
  
33use Test;
44plan tests => 8;
55
6use HTTP::Status;
6use HTTP::Status qw(:constants :is status_message);
77
8ok(RC_OK, 200);
8ok(HTTP_OK, 200);
99
10ok(is_info(RC_CONTINUE));
11ok(is_success(RC_ACCEPTED));
12ok(is_error(RC_BAD_REQUEST));
13ok(is_redirect(RC_MOVED_PERMANENTLY));
10ok(is_info(HTTP_CONTINUE));
11ok(is_success(HTTP_ACCEPTED));
12ok(is_error(HTTP_BAD_REQUEST));
13ok(is_redirect(HTTP_MOVED_PERMANENTLY));
1414
15ok(!is_success(RC_NOT_FOUND));
15ok(!is_success(HTTP_NOT_FOUND));
1616
1717ok(status_message(0), undef);
1818ok(status_message(200), "OK");

Comments

Add a new comment:

Login or create an account to post a comment

Add your comment