EPrints/Filter/Repeated.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 50.0% 5 / 10 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 78.6% 59 / 75 CC 10 SCAR 15.5
CC
10
Cov
83%
new
9.4
fulltext
3.0
AUTOLOAD
2.0
CRAP 4.7
« EPrints/Filter/RobotsTxt.pm ↑ Summary EPrints/Mapping/EPrints.pm »
1 package Logfile::EPrints::Filter::Repeated;
2  
3 6 require bytes;
4 6 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use SDBM_File;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use constant CACHE_TIMEOUT => 60*60*24; # 1 day
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use constant REPEATS_CACHE => '/usr/local/share/Logfile/repeatscache.db';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use vars qw( $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new
12 1 ▶{
Subroutine new: called CC=7 SCAR=22.4
Pod undocumented
13 1 my ($class,%args) = @_;
14 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
15 1 ▶ my $filename = $args{'file'} || REPEATS_CACHE;
Condition50%1/2
$args{'file'} || '/usr/local/share/Logfile/repeatscache.db'
l!l
10
MC/DC0%0/1
$args{'file'} || '/usr/local/share/Logfile/repeatscache.db'
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
Aresult
11
00
16 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 repeats cache database at ${filename}: $!" 1 0 1
17 or die "Unable to open repeats cache database at $filename: $!";
18 1 my @KEYS;
19 1 ▶ while( my ($key, $value) = each %{$self->{cache}} )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"cache"};}) 0 1 1
20 {
21 0 ▶ push @KEYS, $key if( $value < time - CACHE_TIMEOUT );
Branch: 1 branch
BranchTrueFalseTotal
if $value < time - 86400 0 0 0
22 }
23 1 delete $self->{cache}->{$_} for @KEYS;
24 1 $self;
25 }
26  
27 sub DESTROY
28 1 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
29 1 untie %{$_[0]->{cache}};
30 }
31  
32 sub AUTOLOAD
33 360 ▶{
Subroutine AUTOLOAD: called CC=2 SCAR=7.1
34 360 ▶ return if $AUTOLOAD =~ /[A-Z]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $AUTOLOAD =~ /[A-Z]$/ 0 360 360
35 360 $AUTOLOAD =~ s/^.*:://;
36 360 shift->{handler}->$AUTOLOAD(@_);
37 }
38  
39 sub fulltext
40 41 ▶{
Subroutine fulltext: called CC=3 SCAR=11.0
Pod undocumented
41 41 my ($self,$hit) = @_;
42 41 my $r;
43 41 my $key = $hit->address . 'x' . $hit->identifier;
44 41 ▶ if( defined($self->{cache}->{$key}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'cache'}{$key} and $hit->utime - $self->{'cache'}{$key} <= 86400) { } 9 32 41
Condition66%2/3
defined $self->{"cache"}{$key} and $hit->utime - $self->{"cache"}{$key} <= 86400
!ll&&!rl&&r
3209
MC/DC50%1/2
defined $self->{"cache"}{$key} and $hit->utime - $self->{"cache"}{$key} <= 86400
defined $self->{"cache"}{$key} $hit->utime - $self->{"cache"}{$key} <= 86400
Truth table66%2/3
A and B
A= defined $self->{"cache"}{$key}B= $hit->utime - $self->{"cache"}{$key} <= 86400
ABresult
0X0
100
111
45 ($hit->utime - $self->{cache}->{$key}) <= CACHE_TIMEOUT
46 ) {
47 9 $r = $self->{handler}->repeated($hit);
48 } else {
49 32 $r = $self->{handler}->fulltext($hit);
50 }
51 41 $self->{cache}->{$key} = $hit->utime;
52 41 return $r;
53 }
54  
55 6 1;
56  
57 =pod
58  
59 =head1 NAME
60  
61 Logfile::EPrints::Filter::Repeated - Catch fulltext events and check for repeated requests
62  
63 =head1 DESCRIPTION
64  
65 This filter catches fulltext events and either forwards the fulltext event or, if the same identifier has been requested by the same address within 24 hours, create a repeated event.
66  
67 =head1 TODO
68  
69 Free memory by removing requests older than 24 hours.
70  
71 =head1 HANDLER CALLBACKS
72  
73 =over 4
74  
75 =item repeated()
76  
77 =back
78  
79 =cut
« EPrints/Filter/RobotsTxt.pm ↑ Summary EPrints/Mapping/EPrints.pm »