diff --git a/lib/HTTP/Status.pm b/lib/HTTP/Status.pm index eb548174..332b72aa 100644 --- a/lib/HTTP/Status.pm +++ b/lib/HTTP/Status.pm @@ -8,7 +8,7 @@ our $VERSION = '6.45'; use Exporter 5.57 'import'; our @EXPORT = qw(is_info is_success is_redirect is_error status_message); -our @EXPORT_OK = qw(is_client_error is_server_error is_cacheable_by_default status_constant_name); +our @EXPORT_OK = qw(is_client_error is_server_error is_cacheable_by_default status_constant_name status_codes); # Note also addition of mnemonics to @EXPORT below @@ -169,6 +169,8 @@ sub is_cacheable_by_default ($) { $_[0] && ( $_[0] == 200 # OK ); } +sub status_codes { %StatusCode; } + 1; @@ -343,6 +345,12 @@ Section 6.1. Overview of Status Codes|https://tools.ietf.org/html/rfc7231#sectio This function is B exported by default. +=item status_codes + +Returns a hash mapping numerical HTTP status code (e.g. 200) to text status messages (e.g. "OK") + +This function is B exported by default. + =back =head1 SEE ALSO diff --git a/t/status.t b/t/status.t index 9545c389..b1d13cd8 100644 --- a/t/status.t +++ b/t/status.t @@ -2,9 +2,9 @@ use strict; use warnings; use Test::More; -plan tests => 52; +plan tests => 53; -use HTTP::Status qw(:constants :is status_message status_constant_name); +use HTTP::Status qw(:constants :is status_message status_constant_name status_codes); is(HTTP_OK, 200); @@ -56,3 +56,6 @@ ok(!is_cacheable_by_default($_), is(status_constant_name(HTTP_OK), "HTTP_OK"); is(status_constant_name(404), "HTTP_NOT_FOUND"); is(status_constant_name(999), undef); + +my %status_codes = status_codes(); +is($status_codes{200}, status_message(200));