Common/HTTP.pm

filter: Statementstmt 100% 26 / 26 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 90.0% 45 / 50 CC 6 SCAR 5.6
CC
6
Cov
86%
is_info
2.1
is_success
2.1
is_redirect
2.1
CRAP 1.8
↑ Summary Common.pm »
1 package Enum::Declare::Common::HTTP;
2  
3 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Enum::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our @EXPORT = qw(is_info is_success is_redirect is_client_error is_server_error);
10 2 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 2 };
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 2 };
84  
85 # ── Helper functions ──
86  
87 2 ▶sub is_info { my $c = shift; $c >= 100 && $c < 200 }
Subroutine is_info: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$c >= 100 and $c < 200 2 0 2
88 3 ▶sub is_success { my $c = shift; $c >= 200 && $c < 300 }
Subroutine is_success: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$c >= 200 and $c < 300 3 0 3
89 2 ▶sub is_redirect { my $c = shift; $c >= 300 && $c < 400 }
Subroutine is_redirect: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$c >= 300 and $c < 400 2 0 2
90 3 ▶sub is_client_error { my $c = shift; $c >= 400 && $c < 500 }
Subroutine is_client_error: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$c >= 400 and $c < 500 3 0 3
91 2 ▶sub is_server_error { my $c = shift; $c >= 500 && $c < 600 }
Subroutine is_server_error: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$c >= 500 and $c < 600 2 0 2
92  
93 2 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<< <email@lnation.org> >>
142  
143 =head1 LICENSE AND COPYRIGHT
144  
145 Copyright 2026 LNATION. Artistic License 2.0.
146  
147 =cut
↑ Summary Common.pm »