File Coverage

blib/lib/Plack/Middleware/CookieMonster.pm
Criterion Covered Total %
statement 29 29 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 1 1 100.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package Plack::Middleware::CookieMonster;
2 1     1   190272 use strict;
  1         3  
  1         95  
3 1     1   7 use warnings;
  1         2  
  1         52  
4              
5             our $VERSION = '0.02';
6             $VERSION = eval $VERSION;
7              
8 1     1   4 use parent qw/ Plack::Middleware /;
  1         7  
  1         8  
9              
10 1     1   71 use Plack::Util::Accessor qw( cookie_names );
  1         1  
  1         9  
11 1     1   910 use Plack::Request;
  1         62841  
  1         190  
12              
13              
14             sub call {
15 3     3 1 57635 my ( $self, $env ) = @_;
16              
17 3         17 my $res = $self->app->( $env );
18              
19 3 50 33     127212 if ( $env->{ 'plack.stacktrace.html' } && $res->[ 0 ] == 500 ) {
20 3         17 my @cookies = $self->_get_cookie_names( $env );
21 3         10 foreach my $cookie ( @cookies ) {
22 2         4 push @{ $res->[ 1 ] }, 'Set-Cookie', sprintf '%s=deleted; Expires=Sat, 01-May-1971 04:30:01 GMT', $cookie;
  2         13  
23             }
24             }
25              
26 3         36 return $res;
27             }
28              
29             sub _get_cookie_names {
30 13     13   3969 my ( $self, $env ) = @_;
31              
32 13         76 my $sent = Plack::Request->new( $env )->cookies;
33              
34 13 100       781 if ( my $cookie_names = $self->cookie_names ) {
35 9         66 return grep { $sent->{ $_ } } @$cookie_names;
  13         49  
36             }
37             else {
38 4         141 return keys %$sent;
39             }
40             }
41              
42             1;
43              
44             __END__