AnyData/Format/Weblog.pm

filter: Statementstmt 100% 36 / 36 Branchbran 50.0% 3 / 6 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 79.0% 49 / 62 CC 8 SCAR 15.6
CC
8
Cov
86%
read_fields
7.7
new
2.0
BEGIN
1.0
CRAP 4.8
« AnyData/Format/Fixed.pm ↑ Summary AnyData/Format/Text.pm »
1 #########################################################
2 package AnyData::Format::Weblog;
3 #########################################################
4 # AnyData driver for "Common Log Format" web log files
5 # copyright (c) 2000, Jeff Zucker <jeff@vpservices.com>
6 #########################################################
7  
8 =head1 NAME
9  
10 AnyData::Format::Weblog - tiedhash & DBI/SQL access to HTTPD Logs
11  
12 =head1 SYNOPSIS
13  
14 use AnyData;
15 my $weblog = adTie( 'Weblog', $filename );
16 while (my $hit = each %$weblog) {
17 print $hit->{remotehost},"\n" if $hit->{request} =~ /mypage.html/;
18 }
19 # ... other tied hash operations
20  
21 OR
22  
23 use DBI
24 my $dbh = DBI->connect('dbi:AnyData:');
25 $dbh->func('hits','Weblog','access_log','ad_catalog');
26 my $hits = $dbh->selectall_arrayref( qq{
27 SELECT remotehost FROM hits WHERE request LIKE '%mypage.html%'
28 });
29 # ... other DBI/SQL read operations
30  
31 =head1 DESCRIPTION
32  
33 This is a plug-in format parser for the AnyData and DBD::AnyData modules. You can gain read access to Common Log Format files web server log files (e.g. NCSA or Apache) either through tied hashes or arrays or through SQL database queries.
34  
35 Fieldnames are taken from the W3 definitions found at
36  
37 http://www.w3.org/Daemon/User/Config/Logging.html#common-logfile-format
38  
39 remotehost
40 usernname
41 authuser
42 date
43 request
44 status
45 bytes
46  
47 In addition, two extra fields that may be present in extended format logfiles are:
48  
49 referer
50 client
51  
52 This module does not currently support writing to weblog files.
53  
54 Please refer to the documentation for AnyData.pm and DBD::AnyData.pm
55 for further details.
56  
57 =head1 AUTHOR & COPYRIGHT
58  
59 copyright 2000, Jeff Zucker <jeff@vpservices.com>
60 all rights reserved
61  
62 =cut
63  
64 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use AnyData::Format::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶use vars qw( @ISA $DEBUG $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
68 1 @AnyData::Format::Weblog::ISA = qw( AnyData::Format::Base );
69 1 $DEBUG = 0;
70  
71 1 $VERSION = '0.12';
72  
73 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
74 1 my $class = shift;
75 1 ▶ my $self = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
76 $self->{col_names} =
77 1 'remotehost,username,authuser,date,request,status,bytes,referer,client';
78 1 $self->{record_sep} = "\n";
79 1 $self->{key} = 'datestamp';
80 1 $self->{keep_first_line} = 1;
81 1 return bless $self, $class;
82 }
83  
84 2 ▶sub read_fields {
Subroutine read_fields: called CC=7 SCAR=20.4
Pod undocumented
85 2 ▶ print "PARSE RECORD\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $AnyData::Format::Weblog::DEBUG 0 2 2
86 2 my $self = shift;
87 2 ▶ my $str = shift || return undef;
Condition50%1/2
shift() || (return undef)
l!l
20
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
88 2 $str =~ s/^\s+//;
89 2 $str =~ s/\s+$//;
90 2 ▶ return undef unless $str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 2 2
91 2 my (@row) =
92 $str =~ /^(\S*) (\S*) (\S*) \[([^\]]*)\] "(.*?)" (\S*) (\S*)\s*(.*)$/;
93 2 ▶ return undef unless defined $row[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row[0] 0 2 2
94 2 my ( $referer, $client ) = $row[7] =~ /^(.*?)\s(.*)$/;
95 2 ▶ $client ||= '';
Condition50%1/2
$client ||= ""
l!l
20
MC/DC0%0/1
$client ||= ""
$client
Truth table50%1/2
A
A= $client
Aresult
11
00
96 2 ▶ $referer ||= '';
Condition50%1/2
$referer ||= ""
l!l
20
MC/DC0%0/1
$referer ||= ""
$referer
Truth table50%1/2
A
A= $referer
Aresult
11
00
97 2 ( $row[7], $row[8] ) = ( $referer, $client );
98  
99 # $row[3] =~ s/\s*-\s*(\S*)$//; # hide GMT offset on datestamp
100 2 return @row;
101 }
102 1 1;
103  
« AnyData/Format/Fixed.pm ↑ Summary AnyData/Format/Text.pm »