| 1 | package Dancer::HTTP; | ||||||||||
| 2 | 223 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||
| 3 | #ABSTRACT: helper for rendering HTTP status codes for Dancer | ||||||||||
| 4 | 223 | $Dancer::HTTP::VERSION = '1.3520'; | |||||||||
| 5 | 223 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 223 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 223 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 223 | ▶ | use vars '@EXPORT_OK'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 223 | 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 | 223 | 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 | ▶ | my (undef, $name) = @_; | ||||||||
|
Subroutine
status: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 76 | |||||||||||
| 77 | 60 | ▶ | return $name if $name =~ /^\d+$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | |||||||||||
| 79 | 13 | $name =~ s/\W/_/g; | |||||||||
| 80 | 13 | return $STATUS_TO_CODE{lc $name}; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | sub codes { | ||||||||||
| 84 | 0 | ▶ | my %copy = %HTTP_CODES; | ||||||||
|
Subroutine
codes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 85 | 0 | return \%copy; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 223 | 1; | |||||||||
| 89 | |||||||||||
| 90 | __END__ | ||||||||||