lib/W3C/LogValidator/Config.pm

filter: Statementstmt 21.1% 19 / 90 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 42.8% 3 / 7 Podpod 100% 4 / 4 totaltotal 18.4% 26 / 141 CC 20 SCAR 42.0
CC
20
Cov
15%
config_default
111.5
config_file
58.7
new
12.0
CRAP 66.8
« lib/W3C/LogValidator/SurveyEngine.pm ↑ Summary lib/W3C/LogValidator/Output/Mail.pm »
1 # Copyright (c) 2002-2005 the World Wide Web Consortium :
2 # Keio University,
3 # European Research Consortium for Informatics and Mathematics
4 # Massachusetts Institute of Technology.
5 # written by Olivier Thereaux <ot@w3.org> for W3C
6 #
7 # $Id: Config.pm,v 1.13 2008/11/14 15:17:20 ot Exp $
8  
9 package W3C::LogValidator::Config;
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 require Exporter;
13 1 our @ISA = qw(Exporter);
14 1 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
15 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
16 1 our @EXPORT = qw();
17 1 our $VERSION = sprintf "%d.%03d",q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/;
18  
19 1 our $config_filename;
20 1 our %conf;
21  
22 ###########################
23 # usual package interface #
24 ###########################
25 sub new
26 0 ▶{
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
27 0 my $self = {};
28 0 my $proto = shift;
29 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
30 0 $self->{NAME} = undef;
31 0 $self->{SERVERADMIN} = undef;
32 0 $self->{DOCUMENTROOT} = undef;
33 0 $self->{LOGFILES} = undef;
34 0 $self->{LOGFORMAT} = undef;
35 0 $self->{LOGTYPE} = undef;
36 0 $self->{MODULES} = undef;
37 0 $self->{MAX_INVALID} = undef;
38 0 $self->{DIRECTORYINDEX} = undef;
39 0 bless($self, $class);
40 # default values
41  
42 # did we get a config file as an argument?
43 0 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
44 {
45 0 $config_filename = shift;
46 0 $self->config_file;
47 }
48 else
49 {
50 0 $self->config_default;
51 }
52 # $self->give_config; # debug
53 0 return $self;
54 }
55  
56 sub configure
57 0 ▶{
Subroutine configure: not called CC=1 SCAR=6.9
Pod documented
58 0 return %conf;
59 }
60  
61 sub config_default
62 0 ▶{
Subroutine config_default: not called CC=11 SCAR=47.1
Pod documented
63 1 ▶ use Sys::Hostname qw(hostname);
Subroutine BEGIN: called CC=1 SCAR=0.0
64 0 my $self = shift;
65 # setting default values for LogProcessor
66 0 ▶ if (!exists $conf{LogProcessor}{DirectoryIndex})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"DirectoryIndex"}) 0 0 0
67 {
68 0 $conf{LogProcessor}{DirectoryIndex}=("index.html index.htm index");
69 }
70 0 ▶ if (!exists $conf{LogProcessor}{MaxInvalid})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"MaxInvalid"}) 0 0 0
71 {
72 0 $conf{LogProcessor}{MaxInvalid}=10;
73 }
74 0 ▶ if (!exists $conf{LogProcessor}{ServerName})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"ServerName"}) 0 0 0
75 {
76 0 $conf{LogProcessor}{ServerName}=hostname();
77 }
78 0 ▶ if (!exists $conf{LogProcessor}{DocumentRoot})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"DocumentRoot"}) 0 0 0
79 {
80 0 $conf{LogProcessor}{DocumentRoot}="/var/www/";
81 }
82 0 ▶ if (!exists $conf{LogProcessor}{LogFiles})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"LogFiles"}) 0 0 0
83 {
84 0 push @{$conf{LogProcessor}{LogFiles}}, "/var/log/apache/access.log";
85 0 $conf{LogProcessor}{LogType}{"/var/log/apache/access.log"}="common";
86 }
87 0 ▶ if (!exists $conf{LogProcessor}{RefererMatch})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"RefererMatch"}) 0 0 0
88 {
89 0 $conf{LogProcessor}{RefererMatch} =".*";
90 }
91  
92 0 ▶ if (!exists $conf{LogProcessor}{UseValidationModule})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"UseValidationModule"}) 0 0 0
93 {
94 #adding modules and options for the modules
95 0 push @{$conf{LogProcessor}{UseValidationModule}}, "W3C::LogValidator::HTMLValidator";
96 0 push @{$conf{LogProcessor}{UseValidationModule}}, "W3C::LogValidator::Basic";
97 0 $conf{"W3C::LogValidator::HTMLValidator"}{max_invalid}=10;
98 }
99 # adding default limit - useful for very (too) big logfiles
100 0 ▶ if (!exists $conf{LogProcessor}{EntriesPerLogfile})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"EntriesPerLogfile"}) 0 0 0
101 {
102 0 $conf{LogProcessor}{EntriesPerLogfile}=100000;
103 }
104 # adding default handling of URIs with query strings
105 0 ▶ if (!exists $conf{LogProcessor}{ExcludeCGI})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"ExcludeCGI"}) 0 0 0
106 {
107 0 $conf{LogProcessor}{ExcludeCGI}=1;
108 }
109 # parameter muting the final report if nothing interesting to say
110 0 ▶ if (!exists $conf{LogProcessor}{QuietIfNoReport})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $W3C::LogValidator::Config::conf{"LogProcessor"}{"QuietIfNoReport"}) 0 0 0
111 {
112 0 $conf{LogProcessor}{QuietIfNoReport}=0; # not muted by default
113 }
114 }
115  
116  
117  
118 sub config_file
119 0 ▶{
Subroutine config_file: not called CC=8 SCAR=40.7
Pod documented
120 0 my $self = shift;
121 1 ▶ use Config::General;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 0 ▶ my $config_read = new Config::General(-ConfigFile => "$config_filename")
Condition0%0/2
'Config::General'->new('-ConfigFile', "$W3C::LogValidator::Config::config_filename") || die("could not load config $W3C::LogValidator::Config::config_filename : $!")
l!l
00
MC/DC0%0/1
'Config::General'->new('-ConfigFile', "$W3C::LogValidator::Config::config_filename") || die("could not load config $W3C::LogValidator::Config::config_filename : $!")
'Config::General'->new('-ConfigFile', "$W3C::LogValidator::Config::config_filename")
Truth table0%0/2
A
A= 'Config::General'->new('-ConfigFile', "$W3C::LogValidator::Config::config_filename")
Aresult
11
00
123 || die "could not load config $config_filename : $!";
124 # using C::General to read logfile
125 0 my %tmpconf = $config_read->getall;
126 # extracting modules config
127 # Config::General will give the hash this structure
128  
129 # HASH {
130 # foo -> valfoo
131 # bar -> valbar
132 # Module {
133 # module1 {
134 # ga -> valga
135 # }
136 # }
137 # }
138  
139 # and we want
140  
141
142 # HASH {
143 # LogProcessor {
144 # foo -> valfoo
145 # bar -> valbar
146 # }
147 # module1 {
148 # ga -> valga
149 # }
150 # }
151  
152
153 # so First we extract what's in the Module subhash
154 0 ▶ if (exists($tmpconf{Module}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tmpconf{"Module"}) 0 0 0
155 {
156 0 %conf = %{$tmpconf{Module}};
157 }
158 # remove it
159 0 delete $tmpconf{Module};
160 # and merging with the global values we put in the LogProcessor subhash
161 0 %{$conf{LogProcessor}} = %tmpconf;
162  
163 # specific action is needed for "CustomLog"
164 0 ▶ if (exists($tmpconf{CustomLog}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tmpconf{"CustomLog"}) 0 0 0
165 {
166 # if there are several log files, $tmpconf{CustomLog} is an array
167 0 ▶ if (ref($tmpconf{CustomLog}) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tmpconf{'CustomLog'} eq 'ARRAY') { } 0 0 0
168 {
169 0 foreach my $customlog (@{ $tmpconf{CustomLog} })
170 {
171 0 $_ = $customlog;
172 0 ▶ if (/^(.*) (.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (/^(.*) (.*)$/) 0 0 0
173 {
174 # only supported (so far) is the syntax:
175 # CustomLog path/file nickname
176 0 push @{$conf{LogProcessor}{LogFiles}}, $1;
177 0 $conf{LogProcessor}{LogType}{$1}=$2;
178 }
179 }
180  
181 }
182 else # one log file, $tmpconf{CustomLog} is not an array
183 {
184 0 $_ = $tmpconf{CustomLog};
185 0 ▶ if (/^(.*) (.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (/^(.*) (.*)$/) 0 0 0
186 {
187 0 push @{$conf{LogProcessor}{LogFiles}}, $1;
188 0 $conf{LogProcessor}{LogType}{$1}=$2;
189 }
190 }
191 0 delete $conf{LogProcessor}{CustomLog};
192 }
193
194 # add default values for variables not included in the config file
195 0 $self->config_default();
196 }
197  
198 package W3C::LogValidator::Config;
199 1 1;
200  
201 __END__
« lib/W3C/LogValidator/SurveyEngine.pm ↑ Summary lib/W3C/LogValidator/Output/Mail.pm »