lib/Dancer/HTTP.pm

filter: Statementstmt 92.3% 24 / 26 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 91.6% 33 / 36 CC 2 SCAR 3.6
CC
2
Cov
93%
status
2.0
codes
2.0
BEGIN
1.0
CRAP 1.4
« blib/lib/Dancer/Handler/Debug.pm ↑ Summary lib/Dancer/Continuation/Route.pm »
1 package Dancer::HTTP;
2 232 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: helper for rendering HTTP status codes for Dancer
4 232 $Dancer::HTTP::VERSION = '1.3522';
5 232 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 232 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 232 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 232 ▶use vars '@EXPORT_OK';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 232 my %HTTP_CODES = (
11  
12 # informational
13 # 100 => 'Continue', # only on HTTP 1.1
14 # 101 => 'Switching Protocols', # only on HTTP 1.1
15  
16 # processed codes
17 200 => 'OK',
18 201 => 'Created',
19 202 => 'Accepted',
20  
21 # 203 => 'Non-Authoritative Information', # only on HTTP 1.1
22 204 => 'No Content',
23 205 => 'Reset Content',
24 206 => 'Partial Content',
25  
26 # redirections
27 301 => 'Moved Permanently',
28 302 => 'Found',
29  
30 # 303 => '303 See Other', # only on HTTP 1.1
31 304 => 'Not Modified',
32  
33 # 305 => '305 Use Proxy', # only on HTTP 1.1
34 306 => 'Switch Proxy',
35  
36 # 307 => '307 Temporary Redirect', # on HTTP 1.1
37  
38 # problems with request
39 400 => 'Bad Request',
40 401 => 'Unauthorized',
41 402 => 'Payment Required',
42 403 => 'Forbidden',
43 404 => 'Not Found',
44 405 => 'Method Not Allowed',
45 406 => 'Not Acceptable',
46 407 => 'Proxy Authentication Required',
47 408 => 'Request Timeout',
48 409 => 'Conflict',
49 410 => 'Gone',
50 411 => 'Length Required',
51 412 => 'Precondition Failed',
52 413 => 'Request Entity Too Large',
53 414 => 'Request-URI Too Long',
54 415 => 'Unsupported Media Type',
55 416 => 'Requested Range Not Satisfiable',
56 417 => 'Expectation Failed',
57  
58 # problems with server
59 500 => 'Internal Server Error',
60 501 => 'Not Implemented',
61 502 => 'Bad Gateway',
62 503 => 'Service Unavailable',
63 504 => 'Gateway Timeout',
64 505 => 'HTTP Version Not Supported',
65 );
66  
67 232 my %STATUS_TO_CODE = map { my $s = $_; $s =~ s/\W/_/g; lc $s }
68 'error' => 500, # our alias to 500
69 reverse %HTTP_CODES;
70  
71  
72 # always return a numeric status code
73 # if alias, return the corresponding code
74 60 ▶sub status {
Subroutine status: called CC=2 SCAR=6.9
Pod documented
75 60 my (undef, $name) = @_;
76  
77 60 ▶ return $name if $name =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^\d+$/ 47 13 60
78  
79 13 $name =~ s/\W/_/g;
80 13 return $STATUS_TO_CODE{lc $name};
81 }
82  
83 0 ▶sub codes {
Subroutine codes: not called CC=1 SCAR=6.9
Pod documented
84 0 my %copy = %HTTP_CODES;
85 0 return \%copy;
86 }
87  
88 232 1;
89  
90 __END__
« blib/lib/Dancer/Handler/Debug.pm ↑ Summary lib/Dancer/Continuation/Route.pm »