| File: | lib/Yukki/Web/Controller/Redirect.pm |
| Coverage: | 96.3% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Yukki::Web::Controller::Redirect; | ||||||
| 2 | |||||||
| 3 | 1 1 | 477 2 | use v5.24; | ||||
| 4 | 1 1 1 | 3 2 5 | use utf8; | ||||
| 5 | 1 1 1 | 11 2 4 | use Moo; | ||||
| 6 | |||||||
| 7 | 1 1 1 | 1233 2 6 | use Yukki::Error qw( http_throw ); | ||||
| 8 | |||||||
| 9 | 1 1 1 | 215 2 5 | use namespace::clean; | ||||
| 10 | |||||||
| 11 | # ABSTRACT: Simple controller for handling internal redirects | ||||||
| 12 | |||||||
| 13 - 23 | =head1 DESCRIPTION Simple controller for handling internal redirects. =head1 METHODS =head2 fire When fired, performs the requested redirect. =cut | ||||||
| 24 | |||||||
| 25 | sub fire { | ||||||
| 26 | 1 | 1 | 2 | my ($self, $ctx) = @_; | |||
| 27 | |||||||
| 28 | 1 | 14 | my $redirect = $ctx->request->path_parameters->{redirect}; | ||||
| 29 | |||||||
| 30 | 1 | 22 | http_throw("no redirect URL named") unless $redirect; | ||||
| 31 | |||||||
| 32 | 1 | 7 | http_throw("Go to $redirect.", { | ||||
| 33 | status => 'MovedPermanently', | ||||||
| 34 | location => $redirect, | ||||||
| 35 | }); | ||||||
| 36 | } | ||||||
| 37 | |||||||
| 38 | 1; | ||||||