File Coverage

blib/lib/Logfile/Apache.pm
Criterion Covered Total %
statement 25 27 92.5
branch 14 18 77.7
condition 2 3 66.6
subroutine 2 2 100.0
pod 0 2 0.0
total 43 52 82.6


line stmt bran cond sub pod time code
1             package Logfile::Apache;
2             require Logfile::Base;
3              
4             @ISA = qw ( Logfile::Base ) ;
5              
6             sub next {
7 30     30 0 37 my $self = shift;
8 30         64 my $fh = $self->{Fh};
9            
10 30         33 my ($line,$host,$user,$pass,$rest,
11             $date,$req,$code,$bytes,$file,$proto,$hour);
12            
13 30         116 while (defined ($line = <$fh>)) {
14 42         234 ($host,$user,$date,$rest) =
15             $line =~ m,^([^\s]+)\s+-\s+([^ ]+)\s+\[(.*?)\]\s+(.*),;
16 42 100       140 next unless $rest;
17 28         100 $rest =~ s/\"//g;
18 28         94 ($req, $file, $proto, $code, $bytes) = split ' ', $rest;
19 28 50       65 last if $date;
20             }
21            
22 30 100       55 return undef unless $date;
23 28         48 $user =~ s/\s+//g;
24 28 100 66     130 $bytes = 0 unless $bytes ne '-' and $bytes>0;
25 28         98 Logfile::Base::Record->new(Host => $host,
26             Date => $date,
27             File => $file,
28             Bytes => $bytes,
29             User => $user,
30             );
31             }
32              
33             sub norm {
34 140     140 0 182 my ($self, $key, $val) = @_;
35              
36 140 100       318 if ($key eq File) {
    50          
37 28         44 $val =~ s/\?.*//; # remove that !!!
38 28 50       49 $val = '/' unless $val;
39 28         92 $val =~ s/\.\w+$//;
40 28         42 $val =~ s!%([\da-f][\da-f])!chr(hex($1))!eig;
  0         0  
41 28         86 $val =~ s!~(\w+)/.*!~$1!;
42             # proxy
43 28         46 $val =~ s!^((http|ftp|wais)://[^/]+)/.*!$1!;
44             # confine to depth 3
45 28         84 my @val = split /\//, $val;
46 28 100       103 $#val = 2 if $#val > 2;
47             #printf STDERR "$val => %s\n", join('/', @val) || '/';
48 28 50       163 join('/', @val) || '/';
49             } elsif ($key eq Bytes) {
50 0         0 $val =~ s/\D.*//;
51             } else {
52 112         288 $val;
53             }
54             }
55              
56             1;