EPrints/Parser.pm

filter: Statementstmt 95.6% 22 / 23 Branchbran 66.6% 4 / 6 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 5 / 5 Podpod 50.0% 1 / 2 totaltotal 77.2% 34 / 44 CC 6 SCAR 10.8
CC
6
Cov
82%
parse_fh
4.1
new
3.3
BEGIN
1.0
CRAP 3.0
« EPrints/Filter/Session.pm ↑ Summary EPrints/RobotsFilter.pm »
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"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$args{"type"} ||= $args{"parser"}
$args{"type"} $args{"parser"}
Truth table33%1/3
A ||= B
A= $args{"type"}B= $args{"parser"}
ABresult
1X1
011
000
12 2 ▶ $args{type} ||= 'Logfile::EPrints::Hit::Combined';
Condition50%1/2
$args{"type"} ||= "Logfile::EPrints::Hit::Combined"
l!l
02
MC/DC0%0/1
$args{"type"} ||= "Logfile::EPrints::Hit::Combined"
$args{"type"}
Truth table50%1/2
A
A= $args{"type"}
Aresult
11
00
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
BranchTrueFalseTotal
unless my $handler = $self->{"handler"} 0 2 2
20  
21 2 my $hit;
22 2 my $hit_class = $self->{type};
23 2 ▶ while(<$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 2244 2 2246
24 {
25 2244 chomp($_);
26 2244 ▶ if( defined($hit = $hit_class->new($_)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($hit = $hit_class->new($_))) { } 2244 0 2244
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
« EPrints/Filter/Session.pm ↑ Summary EPrints/RobotsFilter.pm »