line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Logfile::EPrints::Parser; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
35
|
use Logfile::EPrints::Hit; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
176
|
|
4
|
6
|
|
|
6
|
|
34
|
use POSIX qw/strftime/; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
53
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
385
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
1464
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new |
9
|
|
|
|
|
|
|
{ |
10
|
2
|
|
|
2
|
1
|
8
|
my ($class,%args) = @_; |
11
|
2
|
|
33
|
|
|
16
|
$args{type} ||= $args{parser}; |
12
|
2
|
|
50
|
|
|
13
|
$args{type} ||= 'Logfile::EPrints::Hit::Combined'; |
13
|
2
|
|
|
|
|
10
|
bless \%args, $class; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub parse_fh |
17
|
|
|
|
|
|
|
{ |
18
|
2
|
|
|
2
|
0
|
11
|
my ($self,$fh) = @_; |
19
|
2
|
50
|
|
|
|
18
|
return unless my $handler = $self->{handler}; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
5
|
my $hit; |
22
|
2
|
|
|
|
|
5
|
my $hit_class = $self->{type}; |
23
|
2
|
|
|
|
|
61
|
while(<$fh>) |
24
|
|
|
|
|
|
|
{ |
25
|
2244
|
|
|
|
|
20111
|
chomp($_); |
26
|
2244
|
50
|
|
|
|
6335
|
if( defined($hit = $hit_class->new($_)) ) { |
27
|
2244
|
|
|
|
|
8173
|
$handler->hit($hit); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
0
|
|
|
|
|
|
Carp::carp("Error parsing: $_"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Logfile::EPrints::Parser - Parse Web server logs that are formatted as one hit per line (e.g. Apache) |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Logfile::EPrints::Parser; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$p = Logfile::EPrints::Parser->new( |
48
|
|
|
|
|
|
|
type=>'Logfile::EPrints::Hit::Combined', |
49
|
|
|
|
|
|
|
handler=>$Handler |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
open my $fh, "
|
53
|
|
|
|
|
|
|
$p->parse_fh($fh); |
54
|
|
|
|
|
|
|
close($fh); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over 4 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item new() |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Create a new Logfile::Parser object with the following options: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
type - Optionally specify a class to parse log file lines with (defaults to ::CombinedLog) |
65
|
|
|
|
|
|
|
handler - Handler to call (see HANDLER CALLBACKS) |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=back |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 HANDLER CALLBACKS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=over 4 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item hit() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |