File Coverage

lib/Plack/Middleware/BotDetector.pm
Criterion Covered Total %
statement 18 18 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 27 28 96.4


line stmt bran cond sub pod time code
1             package Plack::Middleware::BotDetector;
2             # ABSTRACT: Plack middleware to identify bots and spiders
3              
4 1     1   1736 use strict;
  1         2  
  1         66  
5 1     1   5 use warnings;
  1         2  
  1         42  
6              
7 1     1   18 use parent 'Plack::Middleware';
  1         2  
  1         9  
8 1     1   92 use Plack::Util::Accessor 'bot_regex';
  1         2  
  1         10  
9              
10             sub call
11             {
12 6     6 1 53875 my ($self, $env) = @_;
13 6         19 my $user_agent = $env->{HTTP_USER_AGENT};
14 6         34 my $bot_regex = $self->bot_regex;
15              
16 6 50       156 if ($user_agent)
17             {
18 6 100       1237 $env->{'BotDetector.looks-like-bot'}++ if $user_agent =~ qr/$bot_regex/;
19             }
20              
21 6         56 return $self->app->( $env );
22             }
23              
24              
25             1;
26              
27             __END__