File Coverage

blib/lib/Dancer/HTTP.pm
Criterion Covered Total %
statement 16 18 88.8
branch 2 2 100.0
condition n/a
subroutine 5 6 83.3
pod 2 2 100.0
total 25 28 89.2


line stmt bran cond sub pod time code
1             package Dancer::HTTP;
2             our $AUTHORITY = 'cpan:SUKRIA';
3             #ABSTRACT: helper for rendering HTTP status codes for Dancer
4             $Dancer::HTTP::VERSION = '1.3520';
5 190     190   71363 use strict;
  190         449  
  190         5416  
6 190     190   967 use warnings;
  190         410  
  190         5197  
7 190     190   1145 use base 'Exporter';
  190         447  
  190         19373  
8 190     190   1322 use vars '@EXPORT_OK';
  190         453  
  190         65269  
9              
10             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             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             sub status {
75 60     60 1 10337 my (undef, $name) = @_;
76              
77 60 100       414 return $name if $name =~ /^\d+$/;
78              
79 13         43 $name =~ s/\W/_/g;
80 13         72 return $STATUS_TO_CODE{lc $name};
81             }
82              
83             sub codes {
84 0     0 1   my %copy = %HTTP_CODES;
85 0           return \%copy;
86             }
87              
88             1;
89              
90             __END__