EPrints/Filter/Session.pm

filter: Statementstmt 100% 79 / 79 Branchbran 89.2% 25 / 28 Conditioncond 65.0% 13 / 20 MC/DCmcdc 30.7% 4 / 13 Subroutinesub 100% 18 / 18 Podpod 0.0% 0 / 1 totaltotal 87.4% 139 / 159 CC 23 SCAR 14.9
CC
23
Cov
92%
AUTOLOAD
9.1
AUTOLOAD
6.0
AUTOLOAD
5.0
CRAP 4.4
« EPrints/Hit.pm ↑ Summary EPrints/Parser.pm »
1 package Logfile::EPrints::Filter::Session;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use vars qw( %SESSIONS $AUTOLOAD $TIDY_ON $TIDY_COUNT );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 $TIDY_ON = 10000;
8 6 $TIDY_COUNT = 0;
9  
10 sub new
11 3 ▶{
Subroutine new: called CC=3 SCAR=12.0
Pod undocumented
12 3 my ($class,%self) = @_;
13 3 ▶ $self{session} ||= 'Logfile::EPrints::Session';
Condition50%1/2
$self{"session"} ||= "Logfile::EPrints::Session"
l!l
03
MC/DC0%0/1
$self{"session"} ||= "Logfile::EPrints::Session"
$self{"session"}
Truth table50%1/2
A
A= $self{"session"}
Aresult
11
00
14 3 $TIDY_COUNT = 0;
15 3 ▶ bless \%self, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
16 }
17  
18 sub AUTOLOAD
19 27 ▶{
Subroutine AUTOLOAD: called CC=6 SCAR=17.9
20 27 ▶ return if $AUTOLOAD =~ /[A-Z]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $Logfile::EPrints::Filter::Session::AUTOLOAD =~ /[A-Z]$/ 3 24 27
21 24 $AUTOLOAD =~ s/^.*:://;
22 24 my( $self, $hit ) = @_;
23 24 my $address = $hit->address;
24 24 ▶ if( exists $SESSIONS{$address} and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Logfile::EPrints::Filter::Session::SESSIONS{$address} and $Logfile::EPrints::Filter::Session::SESSIONS{$address}->expired_by($hit)) 1 23 24
Condition100%3/3
exists $Logfile::EPrints::Filter::Session::SESSIONS{$address} and $Logfile::EPrints::Filter::Session::SESSIONS{$address}->expired_by($hit)
!ll&&!rl&&r
5181
MC/DC100%2/2
exists $Logfile::EPrints::Filter::Session::SESSIONS{$address} and $Logfile::EPrints::Filter::Session::SESSIONS{$address}->expired_by($hit)
exists $Logfile::EPrints::Filter::Session::SESSIONS{$address} $Logfile::EPrints::Filter::Session::SESSIONS{$address}->expired_by($hit)
Truth table100%3/3
A and B
A= exists $Logfile::EPrints::Filter::Session::SESSIONS{$address}B= $Logfile::EPrints::Filter::Session::SESSIONS{$address}->expired_by($hit)
ABresult
0X0
100
111
25 $SESSIONS{$address}->expired_by( $hit ) )
26 {
27 1 delete($SESSIONS{$address})->end_session;
28 }
29 my $session = $SESSIONS{$address} ||=
30 $self->{session}->new(
31 24 ▶ filter => $self,
Condition66%2/3
$Logfile::EPrints::Filter::Session::SESSIONS{$address} ||= $self->{"session"}->new("filter", $self, "address", $address)
l!l&&r!l&&!r
1860
MC/DC0%0/2
$Logfile::EPrints::Filter::Session::SESSIONS{$address} ||= $self->{"session"}->new("filter", $self, "address", $address)
$Logfile::EPrints::Filter::Session::SESSIONS{$address} $self->{"session"}->new("filter", $self, "address", $address)
Truth table66%2/3
A ||= B
A= $Logfile::EPrints::Filter::Session::SESSIONS{$address}B= $self->{"session"}->new("filter", $self, "address", $address)
ABresult
1X1
011
000
32 address => $address,
33 );
34 24 $session->$AUTOLOAD( $hit );
35
36 24 ▶ $self->_tidyup( $hit ) if ++$TIDY_COUNT > $TIDY_ON;
Branch: 1 branch
BranchTrueFalseTotal
if ++$Logfile::EPrints::Filter::Session::TIDY_COUNT > $Logfile::EPrints::Filter::Session::TIDY_ON 1 23 24
37
38 24 $hit->{session} = $session;
39 24 return $self->{handler}->$AUTOLOAD($hit);
40 }
41  
42 sub _tidyup
43 1 ▶{
Subroutine _tidyup: called CC=3 SCAR=11.0
44 1 my( $self, $hit ) = @_;
45 1 $TIDY_COUNT = 0;
46 1 for(keys %SESSIONS)
47 {
48 2 ▶ if( $SESSIONS{$_}->expired_by( $hit ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($Logfile::EPrints::Filter::Session::SESSIONS{$_}->expired_by($hit)) 1 1 2
49 {
50 1 delete($SESSIONS{$_})->end_session;
51 };
52 }
53 }
54  
55 package Logfile::EPrints::Session;
56  
57 =head1 NAME
58  
59 Logfile::EPrints::Session - Simple session class
60  
61 =head1 METHODS
62  
63 =over 4
64  
65 =cut
66  
67 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 6 ▶use vars qw( $AUTOLOAD $MAX_SESSION_GAP );
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 6 $MAX_SESSION_GAP = 60*10; # 10 minutes
73  
74 sub new
75 6 ▶{
Subroutine new: called CC=1 SCAR=0.0
76 6 my( $class, %self ) = @_;
77 6 bless \%self, $class;
78 }
79  
80 =item $session->expired_by( $hit )
81  
82 Returns true if this session would be expired before $hit occurred. NOTE for the purposes of tidyup $hit may not be from the same address as the session.
83  
84 =cut
85  
86 21 ▶sub expired_by { ($_[1]->utime - $_[0]->{last_seen}) > $MAX_SESSION_GAP }
Subroutine expired_by: called CC=1 SCAR=0.0
87  
88 =item $session->start_session( $hit )
89  
90 A new session has started with $hit.
91  
92 =cut
93  
94 6 ▶sub start_session {}
Subroutine start_session: called CC=1 SCAR=0.0
95  
96 =item $session->end_session
97  
98 The session has expired/finished.
99  
100 =cut
101  
102 2 ▶sub end_session { delete $_[0]->{last_abstract} }
Subroutine end_session: called CC=1 SCAR=0.0
103  
104 =item $session->total( [ $type ] )
105  
106 Return the total number of requests in this session or, if $type is given, total unique requests (by identifier) for $type.
107  
108 =cut
109  
110 sub total
111 11 ▶{
Subroutine total: called CC=2 SCAR=7.1
112 11 my( $self, $type ) = @_;
113  
114 return @_ == 2 ?
115 11 scalar keys %{$self->{requests}->{$type}} :
116 11 ▶ $self->{requests}->{total};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 11 0 11
117 }
118  
119 sub AUTOLOAD
120 28 ▶{
Subroutine AUTOLOAD: called CC=9 SCAR=22.0
121 28 ▶ return if $AUTOLOAD =~ /[A-Z]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $Logfile::EPrints::Session::AUTOLOAD =~ /[A-Z]$/ 4 24 28
122 24 $AUTOLOAD =~ s/^.*:://;
123 24 my( $self, $hit ) = @_;
124  
125 24 ▶ if( !defined $self->{last_seen} )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"last_seen"}) 6 18 24
126 {
127 6 $self->{first_seen} = $hit->utime;
128 6 $self->start_session( $hit );
129 }
130  
131 24 ▶ if( $AUTOLOAD eq 'abstract' )
Branch: 2 branches
BranchTrueFalseTotal
if ($Logfile::EPrints::Session::AUTOLOAD eq 'abstract') { } 1 23 24
elsif ($Logfile::EPrints::Session::AUTOLOAD eq 'fulltext' and exists $self->{'last_abstract'}) { } 3 20 23
132 {
133 1 $self->{last_abstract} = $hit; # creates a loop in this hit
134 }
135 ▶ elsif( $AUTOLOAD eq 'fulltext' and exists $self->{last_abstract} )
Condition66%2/3
$Logfile::EPrints::Session::AUTOLOAD eq "fulltext" and exists $self->{"last_abstract"}
!ll&&!rl&&r
0203
MC/DC50%1/2
$Logfile::EPrints::Session::AUTOLOAD eq "fulltext" and exists $self->{"last_abstract"}
$Logfile::EPrints::Session::AUTOLOAD eq "fulltext" exists $self->{"last_abstract"}
Truth table66%2/3
A and B
A= $Logfile::EPrints::Session::AUTOLOAD eq "fulltext"B= exists $self->{"last_abstract"}
ABresult
0X0
100
111
136 {
137 3 ▶ if( $self->{last_abstract}->identifier eq $hit->identifier )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'last_abstract'}->identifier eq $hit->identifier) { } 2 1 3
138 {
139 2 $hit->{abstract_referrer} = $self->{last_abstract};
140 }
141 else
142 {
143 1 delete $self->{last_abstract};
144 }
145 }
146
147 24 $self->{last_seen} = $hit->utime;
148
149 24 ▶ if( $AUTOLOAD eq 'abstract' or $AUTOLOAD eq 'fulltext' )
Branch: 1 branch
BranchTrueFalseTotal
if ($Logfile::EPrints::Session::AUTOLOAD eq "abstract" or $Logfile::EPrints::Session::AUTOLOAD eq "fulltext") 24 0 24
Condition66%2/3
$Logfile::EPrints::Session::AUTOLOAD eq "abstract" or $Logfile::EPrints::Session::AUTOLOAD eq "fulltext"
l!l&&r!l&&!r
1230
MC/DC0%0/2
$Logfile::EPrints::Session::AUTOLOAD eq "abstract" or $Logfile::EPrints::Session::AUTOLOAD eq "fulltext"
$Logfile::EPrints::Session::AUTOLOAD eq "abstract" $Logfile::EPrints::Session::AUTOLOAD eq "fulltext"
Truth table66%2/3
A or B
A= $Logfile::EPrints::Session::AUTOLOAD eq "abstract"B= $Logfile::EPrints::Session::AUTOLOAD eq "fulltext"
ABresult
1X1
011
000
150 {
151 24 $self->{requests}->{total}++;
152 24 $self->{requests}->{$AUTOLOAD}->{$hit->identifier}++;
153 }
154 }
155  
156 package Logfile::EPrints::Filter::MaxPerSession;
157  
158 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161 6 our @ISA = qw( Logfile::EPrints::Filter );
162  
163 6 ▶use vars qw( $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
164  
165 sub AUTOLOAD
166 12 ▶{
Subroutine AUTOLOAD: called CC=5 SCAR=16.2
167 12 ▶ return if $AUTOLOAD =~ /[A-Z]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD =~ /[A-Z]$/ 1 11 12
168 11 $AUTOLOAD =~ s/^.*:://;
169 11 my( $self, $hit ) = @_;
170 11 ▶ if( defined($self->{$AUTOLOAD}) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD} and $hit->{'session'}->total($Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD) > $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD}) { } 1 10 11
Condition66%2/3
defined $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD} and $hit->{"session"}->total($Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD) > $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD}
!ll&&!rl&&r
0101
MC/DC50%1/2
defined $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD} and $hit->{"session"}->total($Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD) > $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD}
defined $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD} $hit->{"session"}->total($Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD) > $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD}
Truth table66%2/3
A and B
A= defined $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD}B= $hit->{"session"}->total($Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD) > $self->{$Logfile::EPrints::Filter::MaxPerSession::AUTOLOAD}
ABresult
0X0
100
111
171 $hit->{session}->total($AUTOLOAD) > $self->{$AUTOLOAD} )
172 {
173 1 ▶ return undef if $hit->{session}->{__PACKAGE__ . '_removed'};
Branch: 1 branch
BranchTrueFalseTotal
if $hit->{"session"}{"Logfile::EPrints::Filter::MaxPerSession_removed"} 0 1 1
174 1 $hit->{session}->{__PACKAGE__ . '_removed'} = 1;
175 return Logfile::EPrints::Hit::Negate->new(
176 address => $hit->address,
177 start_utime => $hit->{session}->{first_seen},
178 end_utime => $hit->{session}->{last_seen},
179 1 );
180 }
181 else
182 {
183 10 return $self->{handler}->$AUTOLOAD( $hit );
184 }
185 }
186  
187 6 1;
188  
189 __END__
« EPrints/Hit.pm ↑ Summary EPrints/Parser.pm »