| 1 | package Logfile::EPrints::Parser; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 6 | ▶ | use Logfile::EPrints::Hit; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use POSIX qw/strftime/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | sub new | ||||||||||||||||||||
| 9 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||
| 10 | 2 | my ($class,%args) = @_; | |||||||||||||||||||
| 11 | 2 | ▶ | $args{type} ||= $args{parser}; | ||||||||||||||||||
|
Condition33%1/3
$args{"type"} ||= $args{"parser"}
MC/DC0%0/2
$args{"type"} ||= $args{"parser"}
$args{"type"}
$args{"parser"}
Truth table33%1/3
A ||= B
A= $args{"type"}B= $args{"parser"}
| |||||||||||||||||||||
| 12 | 2 | ▶ | $args{type} ||= 'Logfile::EPrints::Hit::Combined'; | ||||||||||||||||||
|
Condition50%1/2
$args{"type"} ||= "Logfile::EPrints::Hit::Combined"
MC/DC0%0/1
$args{"type"} ||= "Logfile::EPrints::Hit::Combined"
$args{"type"}
Truth table50%1/2
A
A= $args{"type"}
| |||||||||||||||||||||
| 13 | 2 | bless \%args, $class; | |||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub parse_fh | ||||||||||||||||||||
| 17 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
parse_fh: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||
| 18 | 2 | my ($self,$fh) = @_; | |||||||||||||||||||
| 19 | 2 | ▶ | return unless my $handler = $self->{handler}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 2 | my $hit; | |||||||||||||||||||
| 22 | 2 | my $hit_class = $self->{type}; | |||||||||||||||||||
| 23 | 2 | ▶ | while(<$fh>) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | { | ||||||||||||||||||||
| 25 | 2244 | chomp($_); | |||||||||||||||||||
| 26 | 2244 | ▶ | if( defined($hit = $hit_class->new($_)) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | 2244 | $handler->hit($hit); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | else { | ||||||||||||||||||||
| 30 | 0 | Carp::carp("Error parsing: $_"); | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 6 | 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, "<access_log" or die $!; | ||||||||||||||||||||
| 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 | ||||||||||||||||||||