Skip to content

Commit

Permalink
add the 'status_code' function for getting all status codes as hash
Browse files Browse the repository at this point in the history
  • Loading branch information
bayashi authored and oalders committed Jan 3, 2023
1 parent 3fdbbcb commit 773f47a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/HTTP/Status.pm
Expand Up @@ -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

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

sub status_codes { %StatusCode; }

1;


Expand Down Expand Up @@ -343,6 +345,12 @@ Section 6.1. Overview of Status Codes|https://tools.ietf.org/html/rfc7231#sectio
This function is B<not> 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<not> exported by default.
=back
=head1 SEE ALSO
Expand Down
7 changes: 5 additions & 2 deletions t/status.t
Expand Up @@ -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);

Expand Down Expand Up @@ -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));

0 comments on commit 773f47a

Please sign in to comment.