File Coverage

blib/lib/Plack/ResponseHelper/Redirect.pm
Criterion Covered Total %
statement 22 22 100.0
branch 4 4 100.0
condition 4 5 80.0
subroutine 6 6 100.0
pod 0 1 0.0
total 36 38 94.7


line stmt bran cond sub pod time code
1             package Plack::ResponseHelper::Redirect;
2 1     1   5 use strict;
  1         10  
  1         35  
3 1     1   6 use warnings;
  1         2  
  1         24  
4              
5 1     1   6 use Carp;
  1         9  
  1         149  
6 1     1   936 use Plack::Response;
  1         15847  
  1         118  
7              
8             sub helper {
9 2     2 0 3 my $init = shift;
10 2   66     11 my $default_location = $init && $init->{default_location};
11 2   100     15 my $status = $init && $init->{default_status} || 302;
12              
13             return sub {
14 4     4   6 my $r = shift;
15 4 100       14 $r = $default_location unless defined $r;
16 4 100       32 croak "No location specified" unless length $r;
17 3         27 my $response = Plack::Response->new();
18 3         66 $response->redirect($r, $status);
19 3         365 return $response;
20 2         14 };
21             }
22              
23             1;
24              
25             __END__