lib/W3C/LogValidator/Basic.pm

filter: Statementstmt 14.5% 7 / 48 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 3 / 6 Podpod n/a totaltotal 12.9% 10 / 77 CC 12 SCAR 36.8
CC
12
Cov
10%
trim_uris
72.0
new
20.0
uris
6.0
CRAP 39.5
« lib/W3C/LogValidator.pm ↑ Summary lib/W3C/LogValidator/Output/HTML.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: Basic.pm,v 1.18 2008/11/18 16:48:56 ot Exp $
8  
9 package W3C::LogValidator::Basic;
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 require Exporter;
15 our @ISA = qw(Exporter);
16 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
17 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
18 our @EXPORT = qw();
19 our $VERSION = sprintf "%d.%03d",q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/;
20  
21  
22 ###########################
23 # usual package interface #
24 ###########################
25 our $verbose = 1;
26 our %config;
27  
28 sub new
29 0 ▶{
Subroutine new: not called CC=4 SCAR=30.0
30 0 my $self = {};
31 0 my $proto = shift;
32 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
33 # mandatory vars for the API
34 0 @{$self->{URIs}} = undef;
35 # don't change this
36 0 ▶ if (@_) {%config = %{(shift)};}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
37 0 ▶ if (exists $config{verbose}) {$verbose = $config{verbose}}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $W3C::LogValidator::Basic::config{"verbose"}) 0 0 0
38 0 bless($self, $class);
39 0 return $self;
40 }
41  
42 0 ▶sub uris {
Subroutine uris: not called CC=2 SCAR=17.9
43 0 my $self = shift;
44 0 ▶ if (@_) { @{$self->{URIs}} = @_ }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
45 0 return @{$self->{URIs}};
46 }
47  
48  
49 sub trim_uris
50 0 ▶{
Subroutine trim_uris: not called CC=8 SCAR=42.8
51 0 my $self = shift;
52 0 my @trimmed_uris;
53 0 my $exclude_regexp = "";
54 0 my @exclude_areas;
55 0 $exclude_regexp = $config{ExcludeAreas};
56 0 ▶ if ($exclude_regexp){
Branch: 1 branch
BranchTrueFalseTotal
if ($exclude_regexp) { } 0 0 0
57 0 $exclude_regexp =~ s/\//\\\//g ;
58 0 @exclude_areas = split(" ", $exclude_regexp);
59 }
60 0 ▶ else { print "nothing to exclude\n" if ($verbose >2);}
Branch: 1 branch
BranchTrueFalseTotal
if $W3C::LogValidator::Basic::verbose > 2 0 0 0
61 0 my $uri;
62 0 ▶ while ($uri = shift)
Branch: 1 branch
BranchTrueFalseTotal
if ($uri = shift()) 0 0 0
63 {
64 0 my $acceptable = 1;
65 0 foreach my $area (@exclude_areas)
66 {
67 0 ▶ if ($uri =~ /$area/)
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ /$area/) 0 0 0
68 {
69 0 my $slasharea = $area;
70 0 $slasharea =~ s/\\\//\//g;
71 0 $slasharea =~ s/\\././g;
72 0 ▶ print "Ignoring $uri matching $slasharea \n" if ($verbose > 2) ;
Branch: 1 branch
BranchTrueFalseTotal
if $W3C::LogValidator::Basic::verbose > 2 0 0 0
73 0 $acceptable = 0;
74 }
75 }
76 0 ▶ push @trimmed_uris,$uri if ($acceptable);
Branch: 1 branch
BranchTrueFalseTotal
if $acceptable 0 0 0
77 }
78 0 return @trimmed_uris;
79 }
80  
81  
82 #########################################
83 # Actual subroutine to check the list of uris #
84 #########################################
85  
86  
87 sub process_list
88 {
89 my $self = shift;
90 my $max_invalid = undef;
91 my $max_documents = undef;
92 if (exists $config{MaxDocuments}) {$max_documents = $config{MaxDocuments}}
93 else {$max_documents = 0}
94  
95 # This basic module does not actually "validates"
96 # so MaxInvalid is not relevant... Keeping it anyway
97 if (exists $config{MaxInvalid}) {$max_invalid = $config{MaxInvalid}}
98 else {$max_invalid = 0}
99 my $name = "";
100 if (exists $config{ServerName}) {$name = $config{ServerName}}
101  
102 print "Now Using the Basic module... \n" if $verbose;
103 my %hits;
104 my %HTTPcodes;
105 my @uris = undef;
106 0 ▶ use DB_File;
Subroutine BEGIN: called CC=1 SCAR=2.6
107 if (defined ($config{tmpfile}))
108 {
109 my $tmp_file = $config{tmpfile};
110 tie (%hits, 'DB_File', "$tmp_file", O_RDONLY) ||
111 die ("Cannot create or open $tmp_file");
112 @uris = sort { $hits{$b} <=> $hits{$a} } keys %hits;
113 }
114  
115 elsif ($self->uris())
116 {
117 @uris = $self->uris();
118 foreach my $uri (@uris) { $hits{$uri} = 0 }
119 }
120  
121 @uris = $self->trim_uris(@uris);
122  
123  
124 if (defined ($config{tmpfile_HTTP_codes}))
125 {
126 my $tmp_file_HTTP_codes = $config{tmpfile_HTTP_codes};
127 tie (%HTTPcodes, 'DB_File', "$tmp_file_HTTP_codes", O_RDONLY) ||
128 die ("Cannot create or open $tmp_file_HTTP_codes");
129 }
130  
131  
132 my $intro="Here are the <census> most popular documents overall for $name.";
133 my @result;
134 my @result_head;
135 push @result_head, "Rank";
136 push @result_head, "Hits";
137 push @result_head, "Address";
138 my $census = 0;
139 while ( (@uris) and (($census < $max_documents) or (!$max_documents)) )
140 {
141 my $uri = shift (@uris);
142 chomp ($uri);
143 my @result_tmp;
144 if (!defined $HTTPcodes{$uri})
145 { # if no HTTP code present, assume it's a 200
146 $census++;
147 push @result_tmp, "$census";
148 push @result_tmp, "$hits{$uri}";
149 push @result_tmp, "$uri";
150 push @result, [@result_tmp];
151 }
152 elsif (($HTTPcodes{$uri} eq "200") or (!$HTTPcodes{$uri} =~ /\d+/))
153 # should perhaps make a subroutine for that instead of DUPing code
154 {
155 $census++;
156 push @result_tmp, "$census";
157 push @result_tmp, "$hits{$uri}";
158 push @result_tmp, "$uri";
159 push @result, [@result_tmp];
160 }
161 elsif ((defined $HTTPcodes{$uri}) and ($verbose > 2)) {
162 print "$uri returned code $HTTPcodes{$uri}, ignoring \n";
163 }
164 }
165 print "Done!\n" if $verbose;
166 if ($census eq 1) # let's repect grammar here
167 {
168 $intro=~ s/are/is/;
169 $intro=~ s/<census> //;
170 $intro=~ s/document\(s\)/document/;
171 }
172 else
173 {
174 $intro=~ s/<census>/$census/;
175 }
176 if (defined ($config{tmpfile})) {
177 untie %hits;
178 }
179 my $outro="";
180 my %returnhash;
181 $returnhash{"name"}="basic";
182 $returnhash{"intro"}=$intro;
183 $returnhash{"outro"}=$outro;
184 @{$returnhash{"thead"}}=@result_head;
185 @{$returnhash{"trows"}}=@result;
186 return %returnhash;
187 }
188  
189 package W3C::LogValidator::Basic;
190  
191 1;
192  
193 __END__
« lib/W3C/LogValidator.pm ↑ Summary lib/W3C/LogValidator/Output/HTML.pm »