File Coverage

blib/lib/Enum/Declare/Common/HTTP.pm
Criterion Covered Total %
statement 21 21 100.0
branch 5 10 50.0
condition n/a
subroutine 9 9 100.0
pod 5 5 100.0
total 40 45 88.8


line stmt bran cond sub pod time code
1             package Enum::Declare::Common::HTTP;
2              
3 2     2   184493 use 5.014;
  2         9  
4 2     2   12 use strict;
  2         6  
  2         82  
5 2     2   11 use warnings;
  2         4  
  2         121  
6              
7 2     2   1096 use Enum::Declare;
  2         22844  
  2         1706  
8              
9             our @EXPORT = qw(is_info is_success is_redirect is_client_error is_server_error);
10             our @EXPORT_OK = @EXPORT;
11              
12             # ── Status Codes (integer enum with explicit values) ──
13              
14             enum StatusCode :Type :Export {
15             Continue = 100,
16             SwitchingProtocols = 101,
17             Processing = 102,
18             EarlyHints = 103,
19              
20             OK = 200,
21             Created = 201,
22             Accepted = 202,
23             NonAuthoritativeInfo = 203,
24             NoContent = 204,
25             ResetContent = 205,
26             PartialContent = 206,
27              
28             MultipleChoices = 300,
29             MovedPermanently = 301,
30             Found = 302,
31             SeeOther = 303,
32             NotModified = 304,
33             TemporaryRedirect = 307,
34             PermanentRedirect = 308,
35              
36             BadRequest = 400,
37             Unauthorized = 401,
38             PaymentRequired = 402,
39             Forbidden = 403,
40             NotFound = 404,
41             MethodNotAllowed = 405,
42             NotAcceptable = 406,
43             RequestTimeout = 408,
44             Conflict = 409,
45             Gone = 410,
46             LengthRequired = 411,
47             PreconditionFailed = 412,
48             PayloadTooLarge = 413,
49             URITooLong = 414,
50             UnsupportedMediaType = 415,
51             RangeNotSatisfiable = 416,
52             ExpectationFailed = 417,
53             ImATeapot = 418,
54             UnprocessableEntity = 422,
55             TooEarly = 425,
56             UpgradeRequired = 426,
57             PreconditionRequired = 428,
58             TooManyRequests = 429,
59             RequestHeaderFieldsTooLarge = 431,
60             UnavailableForLegalReasons = 451,
61              
62             InternalServerError = 500,
63             NotImplemented = 501,
64             BadGateway = 502,
65             ServiceUnavailable = 503,
66             GatewayTimeout = 504,
67             HTTPVersionNotSupported = 505,
68             InsufficientStorage = 507,
69             NetworkAuthenticationRequired = 511
70             };
71              
72             # ── HTTP Methods ──
73              
74             enum Method :Str :Type :Export {
75             GET,
76             POST,
77             PUT,
78             PATCH,
79             DELETE,
80             HEAD,
81             OPTIONS,
82             TRACE
83             };
84              
85             # ── Helper functions ──
86              
87 2 50   2 1 202993 sub is_info { my $c = shift; $c >= 100 && $c < 200 }
  2         25  
88 3 50   3 1 10 sub is_success { my $c = shift; $c >= 200 && $c < 300 }
  3         37  
89 2 50   2 1 6 sub is_redirect { my $c = shift; $c >= 300 && $c < 400 }
  2         20  
90 3 50   3 1 8 sub is_client_error { my $c = shift; $c >= 400 && $c < 500 }
  3         30  
91 2 50   2 1 5 sub is_server_error { my $c = shift; $c >= 500 && $c < 600 }
  2         21  
92              
93             1;
94              
95             =head1 NAME
96              
97             Enum::Declare::Common::HTTP - HTTP status codes, methods, and classification helpers
98              
99             =head1 SYNOPSIS
100              
101             use Enum::Declare::Common::HTTP;
102              
103             say OK; # 200
104             say NotFound; # 404
105             say GET; # "GET"
106              
107             if (is_success($code)) { ... }
108             if (is_client_error($code)) { ... }
109              
110             my $meta = StatusCode();
111             say $meta->name(200); # "OK"
112              
113             =head1 ENUMS
114              
115             =head2 StatusCode :Export
116              
117             Integer enum of standard HTTP status codes (100-511).
118              
119             =head2 Method :Str :Export
120              
121             HTTP method strings: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE.
122              
123             =head1 FUNCTIONS
124              
125             =over 4
126              
127             =item is_info($code) — true for 1xx
128              
129             =item is_success($code) — true for 2xx
130              
131             =item is_redirect($code) — true for 3xx
132              
133             =item is_client_error($code) — true for 4xx
134              
135             =item is_server_error($code) — true for 5xx
136              
137             =back
138              
139             =head1 AUTHOR
140              
141             LNATION C<< >>
142              
143             =head1 LICENSE AND COPYRIGHT
144              
145             Copyright 2026 LNATION. Artistic License 2.0.
146              
147             =cut