| 1 | package Mojolicious::Plugin::HTTPStatusRenderer; | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | # taken from https://metacpan.org/source/GAAS/HTTP-Message-6.06/lib/HTTP/Status.pm | ||||||||||||||||||||
| 9 | 1 | my %StatusCode = ( | |||||||||||||||||||
| 10 | 100 => 'Continue', | ||||||||||||||||||||
| 11 | 101 => 'Switching Protocols', | ||||||||||||||||||||
| 12 | 102 => 'Processing', # RFC 2518 (WebDAV) | ||||||||||||||||||||
| 13 | 200 => 'OK', | ||||||||||||||||||||
| 14 | 201 => 'Created', | ||||||||||||||||||||
| 15 | 202 => 'Accepted', | ||||||||||||||||||||
| 16 | 203 => 'Non-Authoritative Information', | ||||||||||||||||||||
| 17 | 204 => 'No Content', | ||||||||||||||||||||
| 18 | 205 => 'Reset Content', | ||||||||||||||||||||
| 19 | 206 => 'Partial Content', | ||||||||||||||||||||
| 20 | 207 => 'Multi-Status', # RFC 2518 (WebDAV) | ||||||||||||||||||||
| 21 | 208 => 'Already Reported', # RFC 5842 | ||||||||||||||||||||
| 22 | 300 => 'Multiple Choices', | ||||||||||||||||||||
| 23 | 301 => 'Moved Permanently', | ||||||||||||||||||||
| 24 | 302 => 'Found', | ||||||||||||||||||||
| 25 | 303 => 'See Other', | ||||||||||||||||||||
| 26 | 304 => 'Not Modified', | ||||||||||||||||||||
| 27 | 305 => 'Use Proxy', | ||||||||||||||||||||
| 28 | 307 => 'Temporary Redirect', | ||||||||||||||||||||
| 29 | 400 => 'Bad Request', | ||||||||||||||||||||
| 30 | 401 => 'Unauthorized', | ||||||||||||||||||||
| 31 | 402 => 'Payment Required', | ||||||||||||||||||||
| 32 | 403 => 'Forbidden', | ||||||||||||||||||||
| 33 | 404 => 'Not Found', | ||||||||||||||||||||
| 34 | 405 => 'Method Not Allowed', | ||||||||||||||||||||
| 35 | 406 => 'Not Acceptable', | ||||||||||||||||||||
| 36 | 407 => 'Proxy Authentication Required', | ||||||||||||||||||||
| 37 | 408 => 'Request Timeout', | ||||||||||||||||||||
| 38 | 409 => 'Conflict', | ||||||||||||||||||||
| 39 | 410 => 'Gone', | ||||||||||||||||||||
| 40 | 411 => 'Length Required', | ||||||||||||||||||||
| 41 | 412 => 'Precondition Failed', | ||||||||||||||||||||
| 42 | 413 => 'Request Entity Too Large', | ||||||||||||||||||||
| 43 | 414 => 'Request-URI Too Large', | ||||||||||||||||||||
| 44 | 415 => 'Unsupported Media Type', | ||||||||||||||||||||
| 45 | 416 => 'Request Range Not Satisfiable', | ||||||||||||||||||||
| 46 | 417 => 'Expectation Failed', | ||||||||||||||||||||
| 47 | 418 => 'I\'m a teapot', # RFC 2324 | ||||||||||||||||||||
| 48 | 422 => 'Unprocessable Entity', # RFC 2518 (WebDAV) | ||||||||||||||||||||
| 49 | 423 => 'Locked', # RFC 2518 (WebDAV) | ||||||||||||||||||||
| 50 | 424 => 'Failed Dependency', # RFC 2518 (WebDAV) | ||||||||||||||||||||
| 51 | 425 => 'No code', # WebDAV Advanced Collections | ||||||||||||||||||||
| 52 | 426 => 'Upgrade Required', # RFC 2817 | ||||||||||||||||||||
| 53 | 428 => 'Precondition Required', | ||||||||||||||||||||
| 54 | 429 => 'Too Many Requests', | ||||||||||||||||||||
| 55 | 431 => 'Request Header Fields Too Large', | ||||||||||||||||||||
| 56 | 449 => 'Retry with', # unofficial Microsoft | ||||||||||||||||||||
| 57 | 500 => 'Internal Server Error', | ||||||||||||||||||||
| 58 | 501 => 'Not Implemented', | ||||||||||||||||||||
| 59 | 502 => 'Bad Gateway', | ||||||||||||||||||||
| 60 | 503 => 'Service Unavailable', | ||||||||||||||||||||
| 61 | 504 => 'Gateway Timeout', | ||||||||||||||||||||
| 62 | 505 => 'HTTP Version Not Supported', | ||||||||||||||||||||
| 63 | 506 => 'Variant Also Negotiates', # RFC 2295 | ||||||||||||||||||||
| 64 | 507 => 'Insufficient Storage', # RFC 2518 (WebDAV) | ||||||||||||||||||||
| 65 | 509 => 'Bandwidth Limit Exceeded', # unofficial | ||||||||||||||||||||
| 66 | 510 => 'Not Extended', # RFC 2774 | ||||||||||||||||||||
| 67 | 511 => 'Network Authentication Required', | ||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||
| 69 | 1 | my $template = do {local $/; <DATA>}; | |||||||||||||||||||
| 70 | 0 | ▶ | sub register { | ||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 71 | 0 | my ($self, $app, $conf) = @_; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | return $app->routes->any( | |||||||||||||||||||
| 74 | '/httpstatus/*code' => {code => ''} => \&_httpstatus); | ||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | sub _httpstatus { | ||||||||||||||||||
|
Subroutine
_httpstatus: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||
| 79 | 0 | ▶ | my $code = $self->param('code')||$self->req->param('code'); | ||||||||||||||||||
|
Condition0%0/3
$self->param('code') || $self->req->param('code')
MC/DC0%0/2
$self->param('code') || $self->req->param('code')
$self->param('code')
$self->req->param('code')
Truth table0%0/3
A || B
A= $self->param('code')B= $self->req->param('code')
| |||||||||||||||||||||
| 80 | 0 | ▶ | if ( defined $code ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 0 | $code =~ s/[^a-zA-Z0-9]+//g; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | $self->stash(sc => \%StatusCode); | |||||||||||||||||||
| 85 | 0 | ▶ | $self->stash(pcode => $code // ''); | ||||||||||||||||||
|
Condition0%0/2
$code // ""
MC/DC0%0/1
$code // ""
$code
Truth table0%0/2
A
A= $code
| |||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | $self->render(inline => $template, handler => 'ep'); | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | 1 | 1; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =pod | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =head1 NAME | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | Mojolicious::Plugin::HTTPStatusRenderer - HTTP status renderer plugin | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =head1 SYNOPSIS | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | # Mojolicious | ||||||||||||||||||||
| 100 | $self->plugin('HTTPStatusRenderer'); | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | #Mojolicious::Lite | ||||||||||||||||||||
| 103 | plugin 'HTTPStatusRenderer'; | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | # start daemon, and | ||||||||||||||||||||
| 106 | # access http://<host>:<port>/httpstatus/ | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =head1 DESCRIPTION | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | L<Mojolicious::Plugin::HTTPStatusRenderer> is a renderer for novice Web Programmer, rawr! | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =head1 OPTIONS | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | L<Mojolicious::Plugin::HTTPStatusRenderer> supports no options | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head1 METHODS | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | L<Mojolicious::Plugin::HTTPStatusRenderer> inherits all methods from L<Mojolicious::Plugin> and implements the following new ones | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head2 register | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | my $route = $plugin->register(Mojolicious->new); | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head1 SEE ALSO | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | L<Mojoilcious>, L<Mojolicious::Guides>, L<http://mojolicio.us>, L<Mojolicious::Plugin::PODRenderer>, L<App::httpstatus>, L<http://blog.64p.org/entry/2013/02/21/121830> | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =head1 AUTHOR | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | turugina E<lt>turugina@cpan.orgE<gt> | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | =head1 LICENSE | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 136 | it under the same terms as Perl itself. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | __DATA__ | ||||||||||||||||||||