blib/lib/Logfile/Access.pm

filter: Statementstmt 68.1% 253 / 371 Branchbran 27.7% 35 / 126 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 88.3% 53 / 60 Podpod 9.7% 4 / 41 totaltotal 55.9% 346 / 618 CC 70 SCAR 36.6
CC
70
Cov
57%
fix_month
240.0
fix_mday
90.0
fix_year
30.0
CRAP 38.8
↑ Summary
1 package Logfile::Access;
2  
3 # $Id: Access.pm,v 1.30 2004/10/25 18:58:12 root Exp $
4  
5 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Locale::Country;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 require Exporter;
14  
15 1 our @ISA = qw(Exporter);
16  
17 # Items to export into callers namespace by default. Note: do not export
18 # names by default without a very good reason. Use EXPORT_OK instead.
19 # Do not simply export all your public functions/methods/constants.
20  
21 # This allows declaration use Logfile::Access ':all';
22 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
23 # will save memory.
24 1 our %EXPORT_TAGS = ( 'all' => [ qw(
25
26 ) ] );
27  
28 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
29  
30 1 our @EXPORT = qw(
31
32 );
33  
34 1 our $VERSION = '1.30';
35  
36 # Preloaded methods go here.
37  
38 1 ▶use constant MIME_TYPE_CONFIG_FILENAME => "/etc/httpd/conf/mime.types";
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 sub new
41 1 ▶{
Subroutine new: called CC=3 SCAR=11.6
Pod undocumented
42  
43 1 my $self = {};
44 1 my $loop = 1;
45  
46 1 my @column;
47 1 ▶ if (scalar @_ > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) 0 1 1
48 {
49 0 foreach my $key (@column)
50 {
51 0 $self->{$key} = $_[$loop++];
52 }
53 }
54 1 bless($self);
55 1 $self->load_mime_types;
56 1 return $self;
57 }
58  
59 1 my %mime_type;
60 sub load_mime_types
61 1 ▶{
Subroutine load_mime_types: called CC=7 SCAR=33.9
Pod undocumented
62 1 ▶ return if %mime_type;
Branch: 1 branch
BranchTrueFalseTotal
if %mime_type 0 1 1
63 1 ▶ if (open (IN, MIME_TYPE_CONFIG_FILENAME))
Branch: 1 branch
BranchTrueFalseTotal
if (open IN, '/etc/httpd/conf/mime.types') { } 0 1 1
64 {
65 0 ▶ while (<IN>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline IN)) 0 0 0
66 {
67 0 ▶ next if $_ =~ /^ *\#/;
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /^ *\#/ 0 0 0
68 0 $_ =~ s/\n|\r//g;
69 0 my @data = split (/( |\t)+/, $_);
70 0 my $mime_type = shift @data;
71 0 foreach my $extension (@data)
72 {
73 0 ▶ next if $extension !~ /\w/;
Branch: 1 branch
BranchTrueFalseTotal
unless $extension =~ /\w/ 0 0 0
74 0 $mime_type{$extension} = $mime_type;
75 }
76 }
77 0 close IN;
78 }
79 else
80 {
81 1 warn "unable to open " . MIME_TYPE_CONFIG_FILENAME . "\n";
82 }
83 }
84  
85 1 ▶use constant REGEX_IP => q{(\S+)};
Subroutine BEGIN: called CC=1 SCAR=0.0
86 1 ▶use constant REGEX_DATE => q{(\d{2})\/(\w{3})\/(\d{4})};
Subroutine BEGIN: called CC=1 SCAR=0.0
87 1 ▶use constant REGEX_TIME => q{(\d{2}):(\d{2}):(\d{2})};
Subroutine BEGIN: called CC=1 SCAR=0.0
88 1 ▶use constant REGEX_OFFSET => q{([+\-]\d{4})};
Subroutine BEGIN: called CC=1 SCAR=0.0
89 1 ▶use constant REGEX_METHOD => q{(\S+)};
Subroutine BEGIN: called CC=1 SCAR=0.0
90 1 ▶use constant REGEX_OBJECT => q{([^ ]+)};
Subroutine BEGIN: called CC=1 SCAR=0.0
91 1 ▶use constant REGEX_PROTOCOL => q{(\w+\/[\d\.]+)};
Subroutine BEGIN: called CC=1 SCAR=0.0
92 1 ▶use constant REGEX_STATUS => q{(\d+|\-)};
Subroutine BEGIN: called CC=1 SCAR=0.0
93 1 ▶use constant REGEX_CONTENT_LENGTH => q{(\d+|\-)};
Subroutine BEGIN: called CC=1 SCAR=0.0
94 1 ▶use constant REGEX_HTTP_REFERER => q{([^"]+)};
Subroutine BEGIN: called CC=1 SCAR=0.0
95 1 ▶use constant REGEX_HTTP_USER_AGENT => q{([^"]+)};
Subroutine BEGIN: called CC=1 SCAR=0.0
96 1 ▶use constant REGEX_COOKIE => q{([^"]+)};
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 sub parse_iis
99 0 ▶{
Subroutine parse_iis: not called CC=2 SCAR=17.9
Pod undocumented
100 0 my $class = "parse";
101 0 my $self = shift;
102 0 my $row = shift;
103  
104 #1998-11-19 22:48:39 206.175.82.5 - 208.201.133.173 GET /global/images/navlineboards.gif - 200 540 324 157 HTTP/1.0 Mozilla/4.0+(compatible;+MSIE+4.01;+Windows+95) USERID=CustomerA;+IMPID=01234 http://www.loganalyzer.net
105 0 ▶ if ($row =~ /^(\d{4})-(\d{2})-(\d{2}) @{[REGEX_TIME]} @{[REGEX_IP]} @{[REGEX_IP]} @{[REGEX_METHOD]} @{[REGEX_OBJECT]} (\S+) @{[REGEX_STATUS]} (\d+) (\d+) (\d+) (\d+) @{[REGEX_PROTOCOL]} @{[REGEX_HTTP_USER_AGENT]} @{[REGEX_COOKIE]} @{[REGEX_HTTP_REFERER]} *$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($row =~ m[^(\d{4})-(\d{2})-(\d{2}) @{['(\\d{2}):(\\d{2}):(\\d{2})'];} @{['(\\S+)'];} @{['(\\S+)'];} @{['(\\S+)'];} @{['([^ ]+)'];} (\S+) @{['(\\d+|\\-)'];} (\d+) (\d+) (\d+) (\d+) @{['(\\w+\\/[\\d\\.]+)'];} @{['([^"]+)'];} @{['([^"]+)'];} @{['([^"]+)'];} *$]) { } 0 0 0
106 {
107 0 $self->{"date"} = join("/", $1, $2, $3);
108 0 $self->{"year"} = $1;
109 0 $self->{"month"} = $2;
110 0 $self->{"mday"} = $3;
111  
112 0 $self->{"time"} = join(":", $4, $5, $6);
113 0 $self->{"hour"} = $4;
114 0 $self->{"minute"} = $5;
115 0 $self->{"second"} = $6;
116 }
117 else
118 {
119 0 return 0;
120 }
121  
122 0 return $self->{$class}
123 }
124  
125 sub parse
126 2 ▶{
Subroutine parse: called CC=3 SCAR=11.0
Pod undocumented
127 2 my $class = "parse";
128 2 my $self = shift;
129 2 my $row = shift;
130  
131 2 $row =~ s/\n|\r//g;
132  
133 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($row =~ m(^@{['(\\S+)'];} (\S+) (\S+) \[@{['(\\d{2})\\/(\\w{3})\\/(\\d{4})'];}:@{['(\\d{2}):(\\d{2}):(\\d{2})'];} @{['([+\\-]\\d{4})'];}\] \"@{['(\\S+)'];} @{['([^ ]+)'];} @{['(\\w+\\/[\\d\\.]+)'];}\" @{['(\\d+|\\-)'];} @{['(\\d+|\\-)'];} *$) or $row =~ m(^@{['(\\S+)'];} (\S+) (\S+) \[@{['(\\d{2})\\/(\\w{3})\\/(\\d{4})'];}:@{['(\\d{2}):(\\d{2}):(\\d{2})'];} @{['([+\\-]\\d{4})'];}\] \"@{['(\\S+)'];} @{['([^ ]+)'];} @{['(\\w+\\/[\\d\\.]+)'];}\" @{['(\\d+|\\-)'];} @{['(\\d+|\\-)'];} \"?@{['([^"]+)'];}\"? \"?@{['([^"]+)'];}\"?$)) { } 2 0 2
Condition33%1/3
$row =~ m(^@{["(\\S+)"];} (\S+) (\S+) \[@{["(\\d{2})\\/(\\w{3})\\/(\\d{4})"];}:@{["(\\d{2}):(\\d{2}):(\\d{2})"];} @{["([+\\-]\\d{4})"];}\] \"@{["(\\S+)"];} @{["([^ ]+)"];} @{["(\\w+\\/[\\d\\.]+)"];}\" @{["(\\d+|\\-)"];} @{["(\\d+|\\-)"];} *$) or $row =~ m(^@{["(\\S+)"];} (\S+) (\S+) \[@{["(\\d{2})\\/(\\w{3})\\/(\\d{4})"];}:@{["(\\d{2}):(\\d{2}):(\\d{2})"];} @{["([+\\-]\\d{4})"];}\] \"@{["(\\S+)"];} @{["([^ ]+)"];} @{["(\\w+\\/[\\d\\.]+)"];}\" @{["(\\d+|\\-)"];} @{["(\\d+|\\-)"];} \"?@{["([^\"]+)"];}\"? \"?@{["([^\"]+)"];}\"?$)
l!l&&r!l&&!r
020
MC/DC0%0/2
$row =~ m(^@{["(\\S+)"];} (\S+) (\S+) \[@{["(\\d{2})\\/(\\w{3})\\/(\\d{4})"];}:@{["(\\d{2}):(\\d{2}):(\\d{2})"];} @{["([+\\-]\\d{4})"];}\] \"@{["(\\S+)"];} @{["([^ ]+)"];} @{["(\\w+\\/[\\d\\.]+)"];}\" @{["(\\d+|\\-)"];} @{["(\\d+|\\-)"];} *$) or $row =~ m(^@{["(\\S+)"];} (\S+) (\S+) \[@{["(\\d{2})\\/(\\w{3})\\/(\\d{4})"];}:@{["(\\d{2}):(\\d{2}):(\\d{2})"];} @{["([+\\-]\\d{4})"];}\] \"@{["(\\S+)"];} @{["([^ ]+)"];} @{["(\\w+\\/[\\d\\.]+)"];}\" @{["(\\d+|\\-)"];} @{["(\\d+|\\-)"];} \"?@{["([^\"]+)"];}\"? \"?@{["([^\"]+)"];}\"?$)
$row =~ m(^@{["(\\S+)"];} (\S+) (\S+) \[@{["(\\d{2})\\/(\\w{3})\\/(\\d{4})"];}:@{["(\\d{2}):(\\d{2}):(\\d{2})"];} @{["([+\\-]\\d{4})"];}\] \"@{["(\\S+)"];} @{["([^ ]+)"];} @{["(\\w+\\/[\\d\\.]+)"];}\" @{["(\\d+|\\-)"];} @{["(\\d+|\\-)"];} *$) $row =~ m(^@{["(\\S+)"];} (\S+) (\S+) \[@{["(\\d{2})\\/(\\w{3})\\/(\\d{4})"];}:@{["(\\d{2}):(\\d{2}):(\\d{2})"];} @{["([+\\-]\\d{4})"];}\] \"@{["(\\S+)"];} @{["([^ ]+)"];} @{["(\\w+\\/[\\d\\.]+)"];}\" @{["(\\d+|\\-)"];} @{["(\\d+|\\-)"];} \"?@{["([^\"]+)"];}\"? \"?@{["([^\"]+)"];}\"?$)
Truth table33%1/3
A or B
A= $row =~ m(^@{["(\\S+)"];} (\S+) (\S+) \[@{["(\\d{2})\\/(\\w{3})\\/(\\d{4})"];}:@{["(\\d{2}):(\\d{2}):(\\d{2})"];} @{["([+\\-]\\d{4})"];}\] \"@{["(\\S+)"];} @{["([^ ]+)"];} @{["(\\w+\\/[\\d\\.]+)"];}\" @{["(\\d+|\\-)"];} @{["(\\d+|\\-)"];} *$)B= $row =~ m(^@{["(\\S+)"];} (\S+) (\S+) \[@{["(\\d{2})\\/(\\w{3})\\/(\\d{4})"];}:@{["(\\d{2}):(\\d{2}):(\\d{2})"];} @{["([+\\-]\\d{4})"];}\] \"@{["(\\S+)"];} @{["([^ ]+)"];} @{["(\\w+\\/[\\d\\.]+)"];}\" @{["(\\d+|\\-)"];} @{["(\\d+|\\-)"];} \"?@{["([^\"]+)"];}\"? \"?@{["([^\"]+)"];}\"?$)
ABresult
1X1
011
000
134 2 ($row =~ /^@{[REGEX_IP]} (\S+) (\S+) \[@{[REGEX_DATE]}:@{[REGEX_TIME]} @{[REGEX_OFFSET]}\] \"@{[REGEX_METHOD]} @{[REGEX_OBJECT]} @{[REGEX_PROTOCOL]}\" @{[REGEX_STATUS]} @{[REGEX_CONTENT_LENGTH]} *$/)
135 ||
136 2 ($row =~ /^@{[REGEX_IP]} (\S+) (\S+) \[@{[REGEX_DATE]}:@{[REGEX_TIME]} @{[REGEX_OFFSET]}\] \"@{[REGEX_METHOD]} @{[REGEX_OBJECT]} @{[REGEX_PROTOCOL]}\" @{[REGEX_STATUS]} @{[REGEX_CONTENT_LENGTH]} \"?@{[REGEX_HTTP_REFERER]}\"? \"?@{[REGEX_HTTP_USER_AGENT]}\"?$/)
137 )
138 {
139 2 $self->{"remote_host"} = $1;
140 2 $self->{"logname"} = $2;
141 2 $self->{"user"} = $3;
142 2 $self->{"date"} = join("/", $4, $5, $6);
143 2 $self->{"mday"} = $4;
144 2 $self->{"month"} = $5;
145 2 $self->{"year"} = $6;
146 2 $self->{"time"} = join(":", $7, $8, $9);
147 2 $self->{"hour"} = $7;
148 2 $self->{"minute"} = $8;
149 2 $self->{"second"} = $9;
150 2 $self->{"offset"} = $10;
151 2 $self->{"method"} = $11;
152 2 $self->{"object"} = $12;
153 2 $self->{"protocol"} = $13;
154 2 $self->{"response_code"} = $14;
155 2 $self->{"content_length"} = $15;
156 2 $self->{"http_referer"} = $16;
157 2 $self->{"http_user_agent"} = $17;
158 2 return 1;
159 }
160 else
161 {
162 #die $row;
163 0 return 0;
164 }
165 #if (@_) {$self->{$class} = shift}
166 #return $self->{$class}
167 }
168  
169 sub print
170 0 ▶{
Subroutine print: not called CC=2 SCAR=17.9
Pod undocumented
171 0 my $class = "print";
172 0 my $self = shift;
173  
174 0 my $datetime = "[" . $self->{"date"} . ":" . $self->{"time"} . " " . $self->{"offset"} . "]";
175 0 my $object = "\"" . join(" ", $self->{"method"}, $self->{"object"}, $self->{"protocol"}) . "\"";
176 0 print join(" ", $self->{"remote_host"}, $self->{"logname"}, $self->{"user"}, $datetime, $object, $self->{"response_code"}, $self->{"content_length"}, "\n");
177  
178 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
179 0 return $self->{$class}
180 }
181  
182 ## REMOTE HOST RELATED FUNCTIONS
183 sub class_a
184 1 ▶{
Subroutine class_a: called CC=2 SCAR=7.0
Pod undocumented
185 1 my $self = shift;
186
187 1 my $host = $self->remote_host;
188 1 ▶ if ($host =~ /^(\d{1,3}\.)(\d{1,3}\.){2}(\d+)(:\d+)?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /^(\d{1,3}\.)(\d{1,3}\.){2}(\d+)(:\d+)?$/) 1 0 1
189 {
190 1 return $1;
191 }
192 }
193  
194 sub class_b
195 1 ▶{
Subroutine class_b: called CC=2 SCAR=7.0
Pod undocumented
196 1 my $self = shift;
197
198 1 my $host = $self->remote_host;
199 1 ▶ if ($host =~ /^((\d{1,3}\.){2})(\d{1,3}\.)(\d+)(:\d+)?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /^((\d{1,3}\.){2})(\d{1,3}\.)(\d+)(:\d+)?$/) 1 0 1
200 {
201 1 return $1;
202 }
203 }
204  
205 sub class_c
206 1 ▶{
Subroutine class_c: called CC=2 SCAR=7.0
Pod undocumented
207 1 my $self = shift;
208
209 1 my $host = $self->remote_host;
210 1 ▶ if ($host =~ /^((\d{1,3}\.){3})(\d+)(:\d+)?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /^((\d{1,3}\.){3})(\d+)(:\d+)?$/) 1 0 1
211 {
212 1 return $1;
213 }
214 }
215  
216 sub tld
217 4 ▶{
Subroutine tld: called CC=3 SCAR=11.0
Pod undocumented
218 4 my $class = "tld";
219 4 my $self = shift;
220  
221
222 4 ▶ if (my $host = $self->{"remote_host"})
Branch: 1 branch
BranchTrueFalseTotal
if (my $host = $self->{"remote_host"}) 4 0 4
223 {
224 4 ▶ if ($host =~ /\.([a-z]{2,5})$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /\.([a-z]{2,5})$/i) 2 2 4
225 {
226 2 my $tld = $1;
227 2 $tld =~ tr/A-Z/a-z/;
228 2 return $tld;
229 }
230 }
231 }
232  
233 sub country_name
234 2 ▶{
Subroutine country_name: called CC=1 SCAR=0.0
Pod undocumented
235 2 my $class = "country_name";
236 2 my $self = shift;
237  
238 2 my $host = $self->{"remote_host"};
239 2 my $tld = $self->tld;
240 2 $self->{$class} = code2country($tld);
241 2 return $self->{$class};
242 }
243  
244 sub domain
245 2 ▶{
Subroutine domain: called CC=4 SCAR=13.9
Pod undocumented
246 2 my $self = shift;
247  
248 2 my $host = $self->remote_host;
249 2 $host =~ s/:\d+$//;
250
251 2 ▶ return if $host =~ /\.\d+(:\d+)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /\.\d+(:\d+)?$/ 1 1 2
252 do
253 1 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$host =~ /^[\w\-]+\.[\w]+$/ or do { do { $host =~ s/^([^\.]*\.)// or return $host } } 1 1 2
254 2 ▶ $host =~ s/^([^\.]*\.)// || return $host;
Branch: 1 branch
BranchTrueFalseTotal
$host =~ s/^([^\.]*\.)// or return $host 2 0 2
255 }
256 until $host =~ /^[\w\-]+\.[\w]+$/;
257 1 return $host;
258 }
259  
260 sub remote_port
261 0 ▶{
Subroutine remote_port: not called CC=2 SCAR=17.9
Pod undocumented
262 ## THIS IS A USELESS PIECE OF CODE, REMOTE_HOSTS NEVER HAVE PORT NUMBER
263 0 my $class = "remote_port";
264 0 my $self = shift;
265  
266 0 my $host = $self->{"remote_host"};
267 0 ▶ return $1 if $host =~ /:(\d+)\b$/;
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /:(\d+)\b$/ 0 0 0
268 }
269  
270 sub remote_host
271 7 ▶{
Subroutine remote_host: called CC=2 SCAR=7.4
Pod documented
272 7 my $class = "remote_host";
273 7 my $self = shift;
274 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 7 7
275 7 return $self->{$class}
276 }
277  
278 sub logname
279 2 ▶{
Subroutine logname: called CC=2 SCAR=7.4
Pod undocumented
280 2 my $class = "logname";
281 2 my $self = shift;
282 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
283 2 return $self->{$class}
284 }
285  
286 sub user
287 2 ▶{
Subroutine user: called CC=2 SCAR=7.4
Pod undocumented
288 2 my $class = "user";
289 2 my $self = shift;
290 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
291 2 return $self->{$class}
292 }
293  
294 sub date
295 2 ▶{
Subroutine date: called CC=2 SCAR=7.4
Pod documented
296 2 my $class = "date";
297 2 my $self = shift;
298 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
299 2 return $self->{$class}
300 }
301  
302 sub fix_mday
303 0 ▶{
Subroutine fix_mday: not called CC=9 SCAR=45.0
Pod undocumented
304 ## BUG: DOES NOT SUPPORT LEAP YEAR
305 0 my $self = shift;
306 0 my $mday = shift;
307  
308 0 $mday = int($mday);
309 0 ▶ $mday = 1 if $mday < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $mday < 1 0 0 0
310 0 ▶ $mday = 31 if $mday > 31;
Branch: 1 branch
BranchTrueFalseTotal
if $mday > 31 0 0 0
311  
312 0 ▶ if ($self->{"month"} =~ /^(jan|mar|may|jul|aug|oct|dec)$/i)
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'month'} =~ /^(jan|mar|may|jul|aug|oct|dec)$/i) { } 0 0 0
elsif ($self->{'month'} =~ /^(apr|jun|sep|nov)$/i) { } 0 0 0
elsif ($self->{'month'} =~ /^(feb)$/i) { } 0 0 0
313 {
314 0 ▶ $mday = 31 if $mday > 31;
Branch: 1 branch
BranchTrueFalseTotal
if $mday > 31 0 0 0
315 }
316 elsif ($self->{"month"} =~ /^(apr|jun|sep|nov)$/i)
317 {
318 0 ▶ $mday = 30 if $mday > 30;
Branch: 1 branch
BranchTrueFalseTotal
if $mday > 30 0 0 0
319 }
320 elsif ($self->{"month"} =~ /^(feb)$/i)
321 {
322 0 ▶ $mday = 29 if $mday > 29;
Branch: 1 branch
BranchTrueFalseTotal
if $mday > 29 0 0 0
323 }
324
325 0 return $mday;
326 }
327  
328 sub mday
329 2 ▶{
Subroutine mday: called CC=2 SCAR=8.5
Pod undocumented
330 2 my $class = "mday";
331 2 my $self = shift;
332 2 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
333 {
334 0 $self->{$class} = shift;
335 0 $self->{$class} = fix_mday($self, $self->{$class});
336 0 $self->{"date"} = sprintf("%2.2d/%3.3s/%4.4d", $self->{"mday"}, $self->{"month"}, $self->{"year"});
337 }
338 2 return $self->{$class}
339 }
340  
341 sub fix_month
342 0 ▶{
Subroutine fix_month: not called CC=15 SCAR=54.8
Pod undocumented
343 0 my $month = shift;
344  
345 0 ▶ if ($month =~ /^\d+$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($month =~ /^\d+$/) 0 0 0
346 {
347 0 $month %= 12;
348 0 ▶ $month = 12 if $month == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $month == 0 0 0 0
349 }
350  
351 0 ▶ if ($month =~ /^(jan|0?1)$/i)
Branch: 12 branches
BranchTrueFalseTotal
if ($month =~ /^(jan|0?1)$/i) { } 0 0 0
elsif ($month =~ /^(feb|0?2)$/i) { } 0 0 0
elsif ($month =~ /^(mar|0?3)$/i) { } 0 0 0
elsif ($month =~ /^(apr|0?4)$/i) { } 0 0 0
elsif ($month =~ /^(may|0?5)$/i) { } 0 0 0
elsif ($month =~ /^(jun|0?6)$/i) { } 0 0 0
elsif ($month =~ /^(jul|0?7)$/i) { } 0 0 0
elsif ($month =~ /^(aug|0?8)$/i) { } 0 0 0
elsif ($month =~ /^(sep|0?9)$/i) { } 0 0 0
elsif ($month =~ /^(oct|10)$/i) { } 0 0 0
elsif ($month =~ /^(nov|11)$/i) { } 0 0 0
elsif ($month =~ /^(dec|12)$/i) { } 0 0 0
352 {
353 0 $month = "Jan";
354 }
355 elsif ($month =~ /^(feb|0?2)$/i)
356 {
357 0 $month = "Feb";
358 }
359 elsif ($month =~ /^(mar|0?3)$/i)
360 {
361 0 $month = "Mar";
362 }
363 elsif ($month =~ /^(apr|0?4)$/i)
364 {
365 0 $month = "Apr";
366 }
367 elsif ($month =~ /^(may|0?5)$/i)
368 {
369 0 $month = "May";
370 }
371 elsif ($month =~ /^(jun|0?6)$/i)
372 {
373 0 $month = "Jun";
374 }
375 elsif ($month =~ /^(jul|0?7)$/i)
376 {
377 0 $month = "Jul";
378 }
379 elsif ($month =~ /^(aug|0?8)$/i)
380 {
381 0 $month = "Aug";
382 }
383 elsif ($month =~ /^(sep|0?9)$/i)
384 {
385 0 $month = "Sep";
386 }
387 elsif ($month =~ /^(oct|10)$/i)
388 {
389 0 $month = "Oct";
390 }
391 elsif ($month =~ /^(nov|11)$/i)
392 {
393 0 $month = "Nov";
394 }
395 elsif ($month =~ /^(dec|12)$/i)
396 {
397 0 $month = "Dec";
398 }
399 }
400  
401 sub month
402 2 ▶{
Subroutine month: called CC=2 SCAR=8.5
Pod undocumented
403 2 my $class = "month";
404 2 my $self = shift;
405 2 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
406 {
407 0 $self->{$class} = shift;
408 0 $self->{$class} = fix_month($self->{$class});
409 0 $self->{"date"} = sprintf("%2.2d/%3.3s/%4.4d", $self->{"mday"}, $self->{"month"}, $self->{"year"});
410 }
411 2 return $self->{$class}
412 }
413  
414 sub fix_year
415 0 ▶{
Subroutine fix_year: not called CC=5 SCAR=34.0
Pod undocumented
416 0 my $year = shift;
417  
418 ## CLEAN UP DATA
419 0 $year =~ s/\D//g;
420 0 $year = int($year);
421 0 $year =~ s/^(\d{4}).*$/$1/;
422  
423 ## ALLOW FOR SHORTCUTS
424 0 ▶ $year = 1900 + $year if (($year >= 38) && ($year < 100));
Branch: 1 branch
BranchTrueFalseTotal
if $year >= 38 and $year < 100 0 0 0
Condition0%0/3
$year >= 38 and $year < 100
!ll&&!rl&&r
000
MC/DC0%0/2
$year >= 38 and $year < 100
$year >= 38 $year < 100
Truth table0%0/3
A and B
A= $year >= 38B= $year < 100
ABresult
0X0
100
111
425 0 ▶ $year = 2000 + $year if (($year >= 00) && ($year < 38));
Branch: 1 branch
BranchTrueFalseTotal
if $year >= 0 and $year < 38 0 0 0
Condition0%0/3
$year >= 0 and $year < 38
!ll&&!rl&&r
000
MC/DC0%0/2
$year >= 0 and $year < 38
$year >= 0 $year < 38
Truth table0%0/3
A and B
A= $year >= 0B= $year < 38
ABresult
0X0
100
111
426  
427 0 $year = sprintf("%4.4d", $year);
428 0 return $year;
429 }
430  
431 sub year
432 2 ▶{
Subroutine year: called CC=2 SCAR=8.5
Pod undocumented
433 2 my $class = "year";
434 2 my $self = shift;
435 2 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
436 {
437 0 $self->{$class} = shift;
438 0 $self->{$class} = fix_year($self->{$class});
439 0 $self->{"date"} = sprintf("%2.2d/%3.3s/%4.4d", $self->{"mday"}, $self->{"month"}, $self->{"year"});
440 }
441 2 return $self->{$class}
442 }
443  
444 sub time
445 2 ▶{
Subroutine time: called CC=2 SCAR=7.4
Pod documented
446 2 my $class = "time";
447 2 my $self = shift;
448 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
449 2 return $self->{$class}
450 }
451  
452 sub fix_time
453 0 ▶{
Subroutine fix_time: not called CC=3 SCAR=24.8
Pod undocumented
454 0 my $value = shift;
455 0 ▶ $value = "00" if (($value < 0) || ($value > 23));
Branch: 1 branch
BranchTrueFalseTotal
if $value < 0 or $value > 23 0 0 0
Condition0%0/3
$value < 0 or $value > 23
l!l&&r!l&&!r
000
MC/DC0%0/2
$value < 0 or $value > 23
$value < 0 $value > 23
Truth table0%0/3
A or B
A= $value < 0B= $value > 23
ABresult
1X1
011
000
456 0 $value = int($value);
457 0 return $value;
458 }
459  
460 sub hour
461 2 ▶{
Subroutine hour: called CC=2 SCAR=8.5
Pod undocumented
462 2 my $class = "hour";
463 2 my $self = shift;
464 2 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
465 {
466 0 $self->{$class} = shift;
467 0 $self->{$class} = fix_time($self->{$class});
468 0 $self->{"time"} = sprintf("%2.2d:%2.2d:%2.2d", $self->{"hour"}, $self->{"minute"}, $self->{"second"});
469 }
470 2 return $self->{$class}
471 }
472  
473 sub minute
474 2 ▶{
Subroutine minute: called CC=2 SCAR=8.5
Pod undocumented
475 2 my $class = "minute";
476 2 my $self = shift;
477 2 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
478 {
479 0 $self->{$class} = shift;
480 0 $self->{$class} = fix_time($self->{$class});
481 0 $self->{"time"} = sprintf("%2.2d:%2.2d:%2.2d", $self->{"hour"}, $self->{"minute"}, $self->{"second"});
482 }
483 2 return $self->{$class}
484 }
485  
486 sub second
487 2 ▶{
Subroutine second: called CC=2 SCAR=8.5
Pod undocumented
488 2 my $class = "second";
489 2 my $self = shift;
490 2 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
491 {
492 0 $self->{$class} = shift;
493 0 $self->{$class} = fix_time($self->{$class});
494 0 $self->{"time"} = sprintf("%2.2d:%2.2d:%2.2d", $self->{"hour"}, $self->{"minute"}, $self->{"second"});
495 }
496 2 return $self->{$class}
497 }
498  
499 sub offset
500 2 ▶{
Subroutine offset: called CC=2 SCAR=7.4
Pod undocumented
501 2 my $class = "offset";
502 2 my $self = shift;
503 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
504 2 return $self->{$class}
505 }
506  
507 sub method
508 2 ▶{
Subroutine method: called CC=2 SCAR=7.4
Pod undocumented
509 2 my $class = "method";
510 2 my $self = shift;
511 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
512 2 return $self->{$class}
513 }
514  
515 ## OBJECT SPECIFIC ROUTINES
516 sub scheme
517 2 ▶{
Subroutine scheme: called CC=1 SCAR=0.0
Pod undocumented
518 2 my $class = "scheme";
519 2 my $self = shift;
520  
521 2 my $uri = URI->new($self->{"object"});
522 2 return $uri->scheme;
523 }
524  
525 sub query_string
526 2 ▶{
Subroutine query_string: called CC=1 SCAR=0.0
Pod undocumented
527 2 my $class = "query_string";
528 2 my $self = shift;
529  
530 2 my $uri = URI->new($self->{"object"});
531 2 return $uri->query;
532 }
533  
534 sub path
535 4 ▶{
Subroutine path: called CC=1 SCAR=0.0
Pod undocumented
536 4 my $class = "path";
537 4 my $self = shift;
538  
539 4 my $uri = URI->new($self->{"object"});
540 4 return $uri->path;
541 }
542  
543 sub mime_type
544 2 ▶{
Subroutine mime_type: called CC=2 SCAR=7.0
Pod undocumented
545 2 my $self = shift;
546  
547 2 my $object = $self->path;
548 2 ▶ if ($object =~ /\.(\w+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($object =~ /\.(\w+)$/) 2 0 2
549 {
550 2 my $extension = $1;
551 2 $extension =~ tr/A-Z/a-z/;
552 2 return $mime_type{$extension};
553 }
554 }
555  
556 sub unescape_object
557 2 ▶{
Subroutine unescape_object: called CC=1 SCAR=0.0
Pod undocumented
558 2 my $self = shift;
559  
560 2 my $object = $self->{"object"};
561 2 return uri_unescape($object);
562 }
563  
564 sub escape_object
565 2 ▶{
Subroutine escape_object: called CC=1 SCAR=0.0
Pod undocumented
566 2 my $self = shift;
567  
568 2 my $object = $self->{"object"};
569 2 return uri_escape($object);
570 }
571  
572 sub object
573 2 ▶{
Subroutine object: called CC=2 SCAR=7.2
Pod documented
574 2 my $class = "object";
575 2 my $self = shift;
576 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
577 2 uri_unescape($self->{$class});
578 2 return $self->{$class}
579 }
580  
581 sub protocol
582 2 ▶{
Subroutine protocol: called CC=2 SCAR=7.4
Pod undocumented
583 2 my $class = "protocol";
584 2 my $self = shift;
585 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
586 2 return $self->{$class}
587 }
588  
589 sub response_code
590 2 ▶{
Subroutine response_code: called CC=2 SCAR=7.4
Pod undocumented
591 2 my $class = "response_code";
592 2 my $self = shift;
593 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
594 2 return $self->{$class}
595 }
596  
597 sub content_length
598 2 ▶{
Subroutine content_length: called CC=2 SCAR=7.4
Pod undocumented
599 2 my $class = "content_length";
600 2 my $self = shift;
601 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
602 2 return $self->{$class}
603 }
604  
605 sub http_referer
606 2 ▶{
Subroutine http_referer: called CC=2 SCAR=7.4
Pod undocumented
607 2 my $class = "http_referer";
608 2 my $self = shift;
609 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
610 2 return $self->{$class}
611 }
612  
613 sub http_user_agent
614 2 ▶{
Subroutine http_user_agent: called CC=2 SCAR=7.4
Pod undocumented
615 2 my $class = "http_user_agent";
616 2 my $self = shift;
617 0 ▶ if (@_) {$self->{$class} = shift}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
618 2 return $self->{$class}
619 }
620  
621  
622 # Autoload methods go after =cut, and are processed by the autosplit program.
623  
624 1 1;
625 __END__
↑ Summary