File Coverage

blib/lib/Plack/App/Redirect.pm
Criterion Covered Total %
statement 18 25 72.0
branch 0 2 0.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 25 35 71.4


line stmt bran cond sub pod time code
1             package Plack::App::Redirect;
2              
3 2     2   81087 use base qw(Plack::Component);
  2         10  
  2         1085  
4 2     2   27487 use strict;
  2         7  
  2         39  
5 2     2   10 use warnings;
  2         3  
  2         58  
6              
7 2     2   1077 use Plack::Response;
  2         26722  
  2         68  
8 2     2   1238 use Plack::Request;
  2         140239  
  2         83  
9 2     2   21 use Plack::Util::Accessor qw(redirect_url);
  2         4  
  2         22  
10              
11             our $VERSION = 0.01;
12              
13             sub call {
14 0     0 1   my ($self, $env) = @_;
15              
16 0 0         if (defined $self->redirect_url) {
17 0           my $req = Plack::Request->new($env);
18 0           my $res = Plack::Response->new;
19 0           $res->redirect($self->redirect_url.$req->request_uri, 308);
20 0           return $res->finalize;
21             } else {
22             return [
23 0           404,
24             [
25             'content-type' => 'text/html; charset=utf-8',
26             ],
27             ['No redirect.'],
28             ];
29             }
30             }
31              
32             1;
33              
34             __END__