EPrints/Filter/RobotsTxt.pm

filter: Statementstmt 93.4% 43 / 46 Branchbran 57.1% 8 / 14 Conditioncond 50.0% 5 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 75.8% 66 / 87 CC 13 SCAR 17.2
CC
13
Cov
80%
new
9.9
AUTOLOAD
6.2
robotstxt
2.1
CRAP 5.6
« EPrints/Filter.pm ↑ Summary EPrints/Filter/Repeated.pm »
1 package Logfile::EPrints::Filter::RobotsTxt;
2  
3 =head1 NAME
4  
5 Logfile::EPrints::Filter::RobotsTxt - Filter Web log hits using a database of robot's IPs
6  
7 =head1 OPTIONS
8  
9 =over 4
10  
11 =item file
12  
13 Specify the robots DBM file to use.
14  
15 =back
16  
17 =cut
18  
19 6 require bytes;
20 6 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use SDBM_File;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 6 ▶use constant BOT_CACHE => '/usr/local/share/Logfile/botcache.db';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶use constant CACHE_TIMEOUT => 60*60*24*30; # 30 days
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶use vars qw( $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub new
28 1 ▶{
Subroutine new: called CC=7 SCAR=23.0
Pod undocumented
29 1 my ($class,%args) = @_;
30 1 ▶ my $self = bless \%args, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
31 1 ▶ my $filename = $args{'file'} || BOT_CACHE;
Condition50%1/2
$args{'file'} || '/usr/local/share/Logfile/botcache.db'
l!l
10
MC/DC0%0/1
$args{'file'} || '/usr/local/share/Logfile/botcache.db'
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
Aresult
11
00
32 1 ▶ tie %{$self->{cache}}, 'SDBM_File', $filename, O_CREAT|O_RDWR, 0644
Branch: 1 branch
BranchTrueFalseTotal
tie %{$$self{"cache"};}, "SDBM_File", $filename, 66, 420 or die "Unable to open robots cache database at ${filename}: $!" 1 0 1
33 or die "Unable to open robots cache database at $filename: $!";
34 1 my @KEYS;
35 1 ▶ while( my ($key, $value) = each %{$self->{cache}} )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"cache"};}) 0 1 1
36 {
37 0 my ($utime,$agent) = unpack("la*", $value);
38 0 ▶ push @KEYS, $key if( $utime < time - CACHE_TIMEOUT );
Branch: 1 branch
BranchTrueFalseTotal
if $utime < time - 2592000 0 0 0
39 }
40 1 delete $self->{cache}->{$_} for @KEYS;
41 1 $self;
42 }
43  
44 sub DESTROY
45 1 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
46 1 my $self = shift;
47 1 untie %{$self->{cache}};
48 }
49  
50 sub AUTOLOAD
51 1122 ▶{
Subroutine AUTOLOAD: called CC=6 SCAR=18.2
52 1122 $AUTOLOAD =~ s/^.*:://;
53 1122 ▶ return if $AUTOLOAD =~ /[A-Z]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $AUTOLOAD =~ /[A-Z]$/ 0 1122 1122
54 1122 my ($self,$hit) = @_;
55 1122 ▶ if( defined($hit->page) && $hit->page =~ /robots\.txt$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hit->page and $hit->page =~ /robots\.txt$/) 21 1101 1122
Condition66%2/3
defined $hit->page and $hit->page =~ /robots\.txt$/
!ll&&!rl&&r
0110121
MC/DC50%1/2
defined $hit->page and $hit->page =~ /robots\.txt$/
defined $hit->page $hit->page =~ /robots\.txt$/
Truth table66%2/3
A and B
A= defined $hit->pageB= $hit->page =~ /robots\.txt$/
ABresult
0X0
100
111
56 {
57 21 $self->robotstxt($hit);
58 21 return undef;
59 }
60 1101 ▶ if( defined(my $value = $self->{cache}->{$hit->address}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $self->{"cache"}{$hit->address})) 7 1094 1101
61 {
62 #warn "Ignoring hit from " . $hit->address . " (" . $self->{cache}->{$hit->address} . ")";
63 7 my( $utime ) = unpack("l",$value);
64 7 ▶ if( $utime > CACHE_TIMEOUT )
Branch: 1 branch
BranchTrueFalseTotal
if ($utime > 2592000) { } 7 0 7
65 {
66 7 delete $self->{cache}->{$hit->address};
67 }
68 else
69 {
70 0 return undef;
71 }
72 }
73  
74 1101 return $self->{handler}->$AUTOLOAD($hit);
75 }
76  
77 sub robotstxt
78 21 ▶{
Subroutine robotstxt: called CC=2 SCAR=7.2
Pod undocumented
79 21 my ($self,$hit) = @_;
80 #warn "Got new robot: " . join(',',$hit->address,$hit->utime,$hit->agent) . "\n";
81 # SDBM_File format only supports upto 1008 bytes
82 21 ▶ $self->{cache}->{$hit->address} = bytes::substr(pack("la*",$hit->utime,$hit->agent||''),0,1008);
Condition50%1/2
$hit->agent || ''
l!l
210
MC/DC0%0/1
$hit->agent || ''
$hit->agent
Truth table50%1/2
A
A= $hit->agent
Aresult
11
00
83 }
84  
85 6 1;
« EPrints/Filter.pm ↑ Summary EPrints/Filter/Repeated.pm »