GX/HTTP/Status.pm

filter: Statementstmt 96.7% 177 / 183 Branchbran 66.6% 4 / 6 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 90.1% 55 / 61 Podpod 100% 7 / 7 totaltotal 78.1% 243 / 311 CC 14 SCAR 13.1
CC
14
Cov
80%
is_client_error
12.0
is_error
12.0
is_informational
12.0
CRAP 3.7
« GX/Response.pm ↑ Summary GX/Meta/Method.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/HTTP/Status.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::HTTP::Status;
7  
8 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 # ----------------------------------------------------------------------------------------------------------------------
13 # Export mechanism
14 # ----------------------------------------------------------------------------------------------------------------------
15  
16 11 require Exporter;
17  
18 11 our @ISA = qw( Exporter );
19  
20 11 our @EXPORT_OK = qw(
21 is_client_error
22 is_error
23 is_informational
24 is_redirection
25 is_server_error
26 is_success
27 reason_phrase
28 );
29  
30 11 our %EXPORT_TAGS = ( 'constants' => [] );
31  
32  
33 # ----------------------------------------------------------------------------------------------------------------------
34 # Status code constants
35 # ----------------------------------------------------------------------------------------------------------------------
36  
37 11 my %STATUS_CODES = (
38 100 => 'Continue', # RFC 2616 (since HTTP/1.1)
39 101 => 'Switching Protocols', # RFC 2616 (since HTTP/1.1)
40 102 => 'Processing', # RFC 2518 (WebDAV)
41 200 => 'OK', # RFC 2616
42 201 => 'Created', # RFC 2616
43 202 => 'Accepted', # RFC 2616
44 203 => 'Non-Authoritative Information', # RFC 2616 (since HTTP/1.1)
45 204 => 'No Content', # RFC 2616
46 205 => 'Reset Content', # RFC 2616
47 206 => 'Partial Content', # RFC 2616
48 207 => 'Multi-Status', # RFC 4918 (WebDAV)
49 300 => 'Multiple Choices', # RFC 2616
50 301 => 'Moved Permanently', # RFC 2616
51 302 => 'Found', # RFC 2616
52 303 => 'See Other', # RFC 2616 (since HTTP/1.1)
53 304 => 'Not Modified', # RFC 2616
54 305 => 'Use Proxy', # RFC 2616 (since HTTP/1.1)
55 306 => 'Switch Proxy', # no longer used
56 307 => 'Temporary Redirect', # RFC 2616 (since HTTP/1.1)
57 400 => 'Bad Request', # RFC 2616
58 401 => 'Unauthorized', # RFC 2616
59 402 => 'Payment Required', # RFC 2616
60 403 => 'Forbidden', # RFC 2616
61 404 => 'Not Found', # RFC 2616
62 405 => 'Method Not Allowed', # RFC 2616
63 406 => 'Not Acceptable', # RFC 2616
64 407 => 'Proxy Authentication Required', # RFC 2616
65 408 => 'Request Timeout', # RFC 2616
66 409 => 'Conflict', # RFC 2616
67 410 => 'Gone', # RFC 2616
68 411 => 'Length Required', # RFC 2616
69 412 => 'Precondition Failed', # RFC 2616
70 413 => 'Request Entity Too Large', # RFC 2616
71 414 => 'Request-URI Too Long', # RFC 2616
72 415 => 'Unsupported Media Type', # RFC 2616
73 416 => 'Request Range Not Satisfiable', # RFC 2616
74 417 => 'Expectation Failed', # RFC 2616
75 422 => 'Unprocessable Entity', # RFC 4918 (WebDAV)
76 423 => 'Locked', # RFC 4918 (WebDAV)
77 424 => 'Failed Dependency', # RFC 4918 (WebDAV)
78 425 => 'Unordered Collection', # RFC 3648 (WebDAV)
79 426 => 'Upgrade Required', # RFC 2817 (TLS)
80 500 => 'Internal Server Error', # RFC 2616
81 501 => 'Not Implemented', # RFC 2616
82 502 => 'Bad Gateway', # RFC 2616
83 503 => 'Service Unavailable', # RFC 2616
84 504 => 'Gateway Timeout', # RFC 2616
85 505 => 'HTTP Version Not Supported', # RFC 2616
86 506 => 'Variant Also Negotiates', # RFC 2295
87 507 => 'Insufficient Storage', # RFC 4918 (WebDAV)
88 509 => 'Bandwidth Limit Exceeded', # unofficial
89 510 => 'Not Extended' # RFC 2774
90 );
91  
92 {
93  
94 11 ▶ while ( my ( $status, $reason_phrase ) = each %STATUS_CODES ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %STATUS_CODES) 572 11 583
95  
96 572 ( my $constant = uc $reason_phrase ) =~ tr/ \-/__/;
97  
98 572 $constant = "HTTP_$constant";
99  
100 11 ▶ eval "use constant $constant => $status; 1;" or die $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "use constant $constant => $status; 1;" or die $@ 572 0 572
101  
102 572 push @EXPORT_OK, $constant;
103  
104 572 push @{$EXPORT_TAGS{'constants'}}, $constant;
105  
106 }
107  
108 }
109  
110  
111 # ----------------------------------------------------------------------------------------------------------------------
112 # Public functions
113 # ----------------------------------------------------------------------------------------------------------------------
114  
115 0 ▶sub is_client_error {
Subroutine is_client_error: not called CC=3 SCAR=24.8
Pod documented
116  
117 0 ▶ return defined $_[0] && $_[0] >= 400 && $_[0] < 500;
Condition0%0/6
defined $_[0] && $_[0] >= 400 && $_[0] < 500
!ll&&!rl&&r
000
defined $_[0] and $_[0] >= 400
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] && $_[0] >= 400 && $_[0] < 500
defined $_[0] $_[0] >= 400 $_[0] < 500
Truth table0%0/4
A and B && C
A= defined $_[0]B= $_[0] >= 400C= $_[0] < 500
ABCresult
0XX0
10X0
1100
1111
118  
119 }
120  
121 0 ▶sub is_error {
Subroutine is_error: not called CC=3 SCAR=24.8
Pod documented
122  
123 0 ▶ return defined $_[0] && $_[0] >= 400 && $_[0] < 600;
Condition0%0/6
defined $_[0] && $_[0] >= 400 && $_[0] < 600
!ll&&!rl&&r
000
defined $_[0] and $_[0] >= 400
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] && $_[0] >= 400 && $_[0] < 600
defined $_[0] $_[0] >= 400 $_[0] < 600
Truth table0%0/4
A and B && C
A= defined $_[0]B= $_[0] >= 400C= $_[0] < 600
ABCresult
0XX0
10X0
1100
1111
124  
125 }
126  
127 0 ▶sub is_informational {
Subroutine is_informational: not called CC=3 SCAR=24.8
Pod documented
128  
129 0 ▶ return defined $_[0] && $_[0] >= 100 && $_[0] < 200;
Condition0%0/6
defined $_[0] && $_[0] >= 100 && $_[0] < 200
!ll&&!rl&&r
000
defined $_[0] and $_[0] >= 100
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] && $_[0] >= 100 && $_[0] < 200
defined $_[0] $_[0] >= 100 $_[0] < 200
Truth table0%0/4
A and B && C
A= defined $_[0]B= $_[0] >= 100C= $_[0] < 200
ABCresult
0XX0
10X0
1100
1111
130  
131 }
132  
133 0 ▶sub is_redirection {
Subroutine is_redirection: not called CC=3 SCAR=24.8
Pod documented
134  
135 0 ▶ return defined $_[0] && $_[0] >= 300 && $_[0] < 400;
Condition0%0/6
defined $_[0] && $_[0] >= 300 && $_[0] < 400
!ll&&!rl&&r
000
defined $_[0] and $_[0] >= 300
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] && $_[0] >= 300 && $_[0] < 400
defined $_[0] $_[0] >= 300 $_[0] < 400
Truth table0%0/4
A and B && C
A= defined $_[0]B= $_[0] >= 300C= $_[0] < 400
ABCresult
0XX0
10X0
1100
1111
136  
137 }
138  
139 0 ▶sub is_server_error {
Subroutine is_server_error: not called CC=3 SCAR=24.8
Pod documented
140  
141 0 ▶ return defined $_[0] && $_[0] >= 500 && $_[0] < 600;
Condition0%0/6
defined $_[0] && $_[0] >= 500 && $_[0] < 600
!ll&&!rl&&r
000
defined $_[0] and $_[0] >= 500
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] && $_[0] >= 500 && $_[0] < 600
defined $_[0] $_[0] >= 500 $_[0] < 600
Truth table0%0/4
A and B && C
A= defined $_[0]B= $_[0] >= 500C= $_[0] < 600
ABCresult
0XX0
10X0
1100
1111
142  
143 }
144  
145 0 ▶sub is_success {
Subroutine is_success: not called CC=3 SCAR=24.8
Pod documented
146  
147 0 ▶ return defined $_[0] && $_[0] >= 200 && $_[0] < 300;
Condition0%0/6
defined $_[0] && $_[0] >= 200 && $_[0] < 300
!ll&&!rl&&r
000
defined $_[0] and $_[0] >= 200
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] && $_[0] >= 200 && $_[0] < 300
defined $_[0] $_[0] >= 200 $_[0] < 300
Truth table0%0/4
A and B && C
A= defined $_[0]B= $_[0] >= 200C= $_[0] < 300
ABCresult
0XX0
10X0
1100
1111
148  
149 }
150  
151 62 ▶sub reason_phrase {
Subroutine reason_phrase: called CC=2 SCAR=7.6
Pod documented
152  
153 62 ▶ return defined $_[0] ? $STATUS_CODES{$_[0]} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 62 0 62
154  
155 }
156  
157  
158 11 1;
159  
160 __END__
« GX/Response.pm ↑ Summary GX/Meta/Method.pm »