File Coverage

blib/lib/Plack/Middleware/IEnosniff.pm
Criterion Covered Total %
statement 23 23 100.0
branch 3 4 75.0
condition 6 9 66.6
subroutine 7 7 100.0
pod 1 1 100.0
total 40 44 90.9


line stmt bran cond sub pod time code
1             package Plack::Middleware::IEnosniff;
2 2     2   34428 use strict;
  2         5  
  2         77  
3 2     2   10 use warnings;
  2         3  
  2         67  
4 2     2   840 use parent 'Plack::Middleware';
  2         325  
  2         16  
5 2     2   17737 use Plack::Util;
  2         6  
  2         52  
6 2     2   10 use Plack::Util::Accessor qw/only_ie/;
  2         4  
  2         13  
7              
8             our $VERSION = '0.02';
9              
10             sub call {
11 4     4 1 32535 my ($self, $env) = @_;
12              
13 4         24 my $res = $self->app->($env);
14             $self->response_cb($res, sub {
15 4     4   67 my $res = shift;
16 4 50 33     35 if ($res && $res->[0] == 200) {
17 4 100 100     13 if ( !$self->only_ie
      66        
18             || ($env->{HTTP_USER_AGENT} && $env->{HTTP_USER_AGENT} =~ m!MSIE 8!) ) {
19 2         42 my $h = Plack::Util::headers($res->[1]);
20 2         108 $h->set('X-Content-Type-Options' => 'nosniff');
21             }
22             }
23 4         165 });
24             }
25              
26             1;
27              
28             __END__