File Coverage

lib/Plack/Middleware/BotDetector.pm
Criterion Covered Total %
statement 7 7 100.0
branch 3 4 75.0
condition n/a
subroutine 2 2 100.0
pod 1 1 100.0
total 13 14 92.8


line stmt bran cond sub pod time code
1             package Plack::Middleware::BotDetector;
2             # ABSTRACT: Plack middleware to identify bots and spiders
3              
4             # these are useful, but not useful enough for their speed/memory cost here
5             # use strict;
6             # use warnings;
7             # use Plack::Util::Accessor 'bot_regex';
8              
9 1     1   651 use parent 'Plack::Middleware';
  1         2  
  1         10  
10              
11             sub call
12             {
13             # no need to copy these just to put names on them
14             # my ($self, $env) = @_;
15              
16 6 50   6 1 16213 if (my $user_agent = $_[1]->{HTTP_USER_AGENT})
17             {
18 6         96 my $bot_regex = $_[0]->{bot_regex};
19 6 100       81 $_[1]->{'BotDetector.looks-like-bot'}++ if $user_agent =~ qr/$bot_regex/;
20             }
21              
22 6         51 return $_[0]->app->( $_[1] );
23             }
24              
25              
26             1;
27              
28             __END__