| 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"
MC/DC0%0/1
$self{"session"} ||= "Logfile::EPrints::Session"
$self{"session"}
Truth table50%1/2
A
A= $self{"session"}
| |||||||||||||||||||||||||||||
| 14 | 3 | $TIDY_COUNT = 0; | |||||||||||||||||||||||||||
| 15 | 3 | ▶ | bless \%self, ref($class) || $class; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
exists $Logfile::EPrints::Filter::Session::SESSIONS{$address} and $Logfile::EPrints::Filter::Session::SESSIONS{$address}->expired_by($hit)
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)
| |||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||
| 32 | address => $address, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | 24 | $session->$AUTOLOAD( $hit ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 24 | ▶ | $self->_tidyup( $hit ) if ++$TIDY_COUNT > $TIDY_ON; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 122 | 24 | $AUTOLOAD =~ s/^.*:://; | |||||||||||||||||||||||||||
| 123 | 24 | my( $self, $hit ) = @_; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 24 | ▶ | if( !defined $self->{last_seen} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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"}
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"}
| |||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||
| 137 | 3 | ▶ | if( $self->{last_abstract}->identifier eq $hit->identifier ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$Logfile::EPrints::Session::AUTOLOAD eq "abstract" or $Logfile::EPrints::Session::AUTOLOAD eq "fulltext"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 168 | 11 | $AUTOLOAD =~ s/^.*:://; | |||||||||||||||||||||||||||
| 169 | 11 | my( $self, $hit ) = @_; | |||||||||||||||||||||||||||
| 170 | 11 | ▶ | if( defined($self->{$AUTOLOAD}) and | ||||||||||||||||||||||||||
|
Branch: 1 branch
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}
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}
| |||||||||||||||||||||||||||||
| 171 | $hit->{session}->total($AUTOLOAD) > $self->{$AUTOLOAD} ) | ||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||
| 173 | 1 | ▶ | return undef if $hit->{session}->{__PACKAGE__ . '_removed'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||