Skip to content

Commit 3e2aba0

Browse files
bayashioalders
authored andcommitted
add the 'status_code' function for getting all status codes as hash
1 parent 3fdbbcb commit 3e2aba0

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Revision history for HTTP-Message
33
{{$NEXT}}
44
- Allow for file ownership conflicts with Docker and GitHub Actions
55
(GH#193) (Olaf Alders)
6+
- Add the 'status_code' function for getting all status codes as hash
7+
(GH#194) (Dai Okabayashi)
68

79
6.44 2022-10-26 20:49:00Z
810
- Made the Clone module a hard requirement, so we don't have to

lib/HTTP/Status.pm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ our $VERSION = '6.45';
88
use Exporter 5.57 'import';
99

1010
our @EXPORT = qw(is_info is_success is_redirect is_error status_message);
11-
our @EXPORT_OK = qw(is_client_error is_server_error is_cacheable_by_default status_constant_name);
11+
our @EXPORT_OK = qw(is_client_error is_server_error is_cacheable_by_default status_constant_name status_codes);
1212

1313
# Note also addition of mnemonics to @EXPORT below
1414

@@ -169,6 +169,8 @@ sub is_cacheable_by_default ($) { $_[0] && ( $_[0] == 200 # OK
169169
);
170170
}
171171

172+
sub status_codes { %StatusCode; }
173+
172174
1;
173175

174176

@@ -343,6 +345,12 @@ Section 6.1. Overview of Status Codes|https://tools.ietf.org/html/rfc7231#sectio
343345
344346
This function is B<not> exported by default.
345347
348+
=item status_codes
349+
350+
Returns a hash mapping numerical HTTP status code (e.g. 200) to text status messages (e.g. "OK")
351+
352+
This function is B<not> exported by default.
353+
346354
=back
347355
348356
=head1 SEE ALSO

t/status.t

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use strict;
22
use warnings;
33

44
use Test::More;
5-
plan tests => 52;
5+
plan tests => 53;
66

7-
use HTTP::Status qw(:constants :is status_message status_constant_name);
7+
use HTTP::Status qw(:constants :is status_message status_constant_name status_codes);
88

99
is(HTTP_OK, 200);
1010

@@ -56,3 +56,6 @@ ok(!is_cacheable_by_default($_),
5656
is(status_constant_name(HTTP_OK), "HTTP_OK");
5757
is(status_constant_name(404), "HTTP_NOT_FOUND");
5858
is(status_constant_name(999), undef);
59+
60+
my %status_codes = status_codes();
61+
is($status_codes{200}, status_message(200));

0 commit comments

Comments
 (0)