lib/Dancer2/Core/HTTP.pm

filter: Statementstmt 96.7% 30 / 31 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 93.6% 59 / 63 CC 8 SCAR 9.4
CC
8
Cov
93%
status
4.1
status_message
4.0
__ANON__
2.0
CRAP 2.5
« blib/lib/Dancer2/Plugin.pm ↑ Summary lib/Dancer2/Core/Role/ConfigReader.pm »
1 # ABSTRACT: helper for rendering HTTP status codes for Dancer2
2  
3 package Dancer2::Core::HTTP;
4 191 $Dancer2::Core::HTTP::VERSION = '2.3.0';
5 191 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 191 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 191 ▶use List::Util qw/ pairmap pairgrep /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 191 my $HTTP_CODES = {
11  
12 # informational
13 100 => 'Continue', # only on HTTP 1.1
14 101 => 'Switching Protocols', # only on HTTP 1.1
15 102 => 'Processing', # WebDAV; RFC 2518
16  
17 # processed
18 200 => 'OK',
19 201 => 'Created',
20 202 => 'Accepted',
21 203 => 'Non-Authoritative Information', # only on HTTP 1.1
22 204 => 'No Content',
23 205 => 'Reset Content',
24 206 => 'Partial Content',
25 207 => 'Multi-Status', # WebDAV; RFC 4918
26 208 => 'Already Reported', # WebDAV; RFC 5842
27 # 226 => 'IM Used' # RFC 3229
28  
29 # redirections
30 301 => 'Moved Permanently',
31 302 => 'Found',
32 303 => 'See Other', # only on HTTP 1.1
33 304 => 'Not Modified',
34 305 => 'Use Proxy', # only on HTTP 1.1
35 306 => 'Switch Proxy',
36 307 => 'Temporary Redirect', # only on HTTP 1.1
37 # 308 => 'Permanent Redirect' # approved as experimental RFC
38  
39 # problems with request
40 400 => 'Bad Request',
41 401 => 'Unauthorized',
42 402 => 'Payment Required',
43 403 => 'Forbidden',
44 404 => 'Not Found',
45 405 => 'Method Not Allowed',
46 406 => 'Not Acceptable',
47 407 => 'Proxy Authentication Required',
48 408 => 'Request Timeout',
49 409 => 'Conflict',
50 410 => 'Gone',
51 411 => 'Length Required',
52 412 => 'Precondition Failed',
53 413 => 'Request Entity Too Large',
54 414 => 'Request-URI Too Long',
55 415 => 'Unsupported Media Type',
56 416 => 'Requested Range Not Satisfiable',
57 417 => 'Expectation Failed',
58 418 => "I'm a teapot", # RFC 2324
59 # 419 => 'Authentication Timeout', # not in RFC 2616
60 420 => 'Enhance Your Calm',
61 422 => 'Unprocessable Entity',
62 423 => 'Locked',
63 424 => 'Failed Dependency', # Also used for 'Method Failure'
64 425 => 'Unordered Collection',
65 426 => 'Upgrade Required',
66 428 => 'Precondition Required',
67 429 => 'Too Many Requests',
68 431 => 'Request Header Fields Too Large',
69 444 => 'No Response',
70 449 => 'Retry With',
71 450 => 'Blocked by Windows Parental Controls',
72 451 => 'Unavailable For Legal Reasons',
73 494 => 'Request Header Too Large',
74 495 => 'Cert Error',
75 496 => 'No Cert',
76 497 => 'HTTP to HTTPS',
77 499 => 'Client Closed Request',
78  
79 # problems with server
80 500 => 'Internal Server Error',
81 501 => 'Not Implemented',
82 502 => 'Bad Gateway',
83 503 => 'Service Unavailable',
84 504 => 'Gateway Timeout',
85 505 => 'HTTP Version Not Supported',
86 506 => 'Variant Also Negotiates',
87 507 => 'Insufficient Storage',
88 508 => 'Loop Detected',
89 509 => 'Bandwidth Limit Exceeded',
90 510 => 'Not Extended',
91 511 => 'Network Authentication Required',
92 598 => 'Network read timeout error',
93 599 => 'Network connect timeout error',
94 };
95  
96 $HTTP_CODES = {
97 %$HTTP_CODES,
98 ( reverse %$HTTP_CODES ),
99 13370 ▶ pairmap { join( '_', split /\W/, lc $a ) => $b } reverse %$HTTP_CODES
Subroutine __ANON__: called CC=1 SCAR=0.0
100 };
101  
102 191 $HTTP_CODES->{error} = $HTTP_CODES->{internal_server_error};
103  
104 1077 ▶sub status {
Subroutine status: called CC=4 SCAR=14.0
Pod documented
105 1077 my ( $class, $status ) = @_;
106 1077 ▶ return if ! defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 1 1076 1077
107 1076 ▶ return $status if $status =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $status =~ /^\d+$/ 1069 7 1076
108 7 ▶ if ( exists $HTTP_CODES->{$status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $HTTP_CODES->{$status}) 7 0 7
109 7 return $HTTP_CODES->{$status};
110 }
111 0 return;
112 }
113  
114 196 ▶sub status_message {
Subroutine status_message: called CC=4 SCAR=13.9
Pod documented
115 196 my ( $class, $status ) = @_;
116 196 ▶ return if ! defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 1 195 196
117 195 my $code = $class->status($status);
118 195 ▶ return if ! defined $code || ! exists $HTTP_CODES->{$code};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code and exists $HTTP_CODES->{$code} 2 193 195
Condition66%2/3
defined $code and exists $HTTP_CODES->{$code}
!ll&&!rl&&r
02193
MC/DC50%1/2
defined $code and exists $HTTP_CODES->{$code}
defined $code exists $HTTP_CODES->{$code}
Truth table66%2/3
A and B
A= defined $codeB= exists $HTTP_CODES->{$code}
ABresult
0X0
100
111
119 193 return $HTTP_CODES->{ $code };
120 }
121  
122 2 ▶sub status_mapping {
Subroutine status_mapping: called CC=1 SCAR=0.0
Pod documented
123 2 ▶ pairgrep { $b =~ /^\d+$/ and $a !~ /_/ } %$HTTP_CODES;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$b =~ /^\d+$/ and not $a =~ /_/ 282 140 422
124 }
125  
126 1 ▶sub code_mapping {
Subroutine code_mapping: called CC=1 SCAR=0.0
Pod documented
127 1 my @result = reverse status_mapping();
128 1 return @result;
129 }
130  
131 1 ▶sub all_mappings { %$HTTP_CODES }
Subroutine all_mappings: called CC=1 SCAR=0.0
Pod documented
132  
133 191 1;
134  
135 __END__
« blib/lib/Dancer2/Plugin.pm ↑ Summary lib/Dancer2/Core/Role/ConfigReader.pm »