DemoUsage.pm

filter: Statementstmt 14.8% 55 / 371 Branchbran 0.0% 0 / 110 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 22.2% 6 / 27 Podpod 10.0% 1 / 10 totaltotal 11.2% 62 / 549 CC 74 SCAR 49.2
CC
74
Cov
11%
update_referrer_counts
420.0
email_and_reset_counts_if_new_day
240.0
send_email_message
90.0
CRAP 136.5
« CGI/Portable/AdapterCGI.pm ↑ Summary CGI/Portable.pm »
1 =head1 NAME
2  
3 DemoUsage - Demo of CGI::Portable that tracks web site usage details,
4 as well as e-mail backups of usage counts to the site owner.
5  
6 =cut
7  
8 ######################################################################
9  
10 package DemoUsage;
11 1 require 5.004;
12  
13 # Copyright (c) 1999-2004, Darren R. Duncan. All rights reserved. This module
14 # is free software; you can redistribute it and/or modify it under the same terms
15 # as Perl itself. However, I do request that this copyright information and
16 # credits remain attached to the file. If you modify this module and
17 # redistribute a changed version then please attach a note listing the
18 # modifications. This module is available "as-is" and the author can not be held
19 # accountable for any problems resulting from its use.
20  
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 $VERSION = '0.51';
25  
26 ######################################################################
27  
28 =head1 DEPENDENCIES
29  
30 =head2 Perl Version
31  
32 5.004
33  
34 =head2 Standard Modules
35  
36 Fcntl
37 Symbol
38 Net::SMTP 2.15 (earlier versions may work)
39  
40 =head2 Nonstandard Modules
41  
42 CGI::Portable 0.50
43  
44 =cut
45  
46 ######################################################################
47  
48 1 ▶use CGI::Portable 0.50;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 ######################################################################
51  
52 =head1 SYNOPSIS
53  
54 =head2 A multiple page website with static html, mail, gb, redir, usage tracking
55  
56 #!/usr/bin/perl
57 use strict;
58 use warnings;
59  
60 require CGI::Portable;
61 my $globals = CGI::Portable->new();
62  
63 use Cwd;
64 $globals->file_path_root( cwd() ); # let us default to current working dir
65 $globals->file_path_delimiter( $^O=~/Mac/i ? ":" : $^O=~/Win/i ? "\\" : "/" );
66  
67 require CGI::Portable::AdapterCGI;
68 my $io = CGI::Portable::AdapterCGI->new();
69 $io->fetch_user_input( $globals );
70  
71 if( $globals->user_query_param( 'debugging' ) eq 'on' ) {
72 $globals->is_debug( 1 );
73 $globals->url_query_param( 'debugging', 'on' );
74 }
75
76 $globals->default_application_title( 'Demo Web Site' );
77 $globals->default_maintainer_name( 'Tony Simons' );
78 $globals->default_maintainer_email_address( 'tony@aardvark.net' );
79 $globals->default_maintainer_email_screen_url_path( '/mailme' );
80  
81 my $content = $globals->make_new_context();
82 $content->current_user_path_level( 1 );
83 $content->navigate_file_path( 'content' );
84 $content->set_prefs( 'content_prefs.pl' );
85 $content->call_component( 'CGI::Portable::AppSplitScreen' );
86 $globals->take_context_output( $content );
87  
88 my $usage = $globals->make_new_context();
89 $usage->http_redirect_url( $globals->http_redirect_url() );
90 $usage->navigate_file_path( $globals->is_debug() ? 'usage_debug' : 'usage' );
91 $usage->set_prefs( '../usage_prefs.pl' );
92 $usage->call_component( 'DemoUsage' );
93 $globals->take_context_output( $usage, 1 );
94  
95 if( $globals->is_debug() ) {
96 $globals->append_page_body( <<__endquote );
97 <p>Debugging is currently turned on.</p>
98 __endquote
99 }
100  
101 $globals->search_and_replace_url_path_tokens( '__url_path__' );
102  
103 $io->send_user_output( $globals );
104  
105 1;
106  
107 =head2 Content of settings file "content_prefs.pl"
108  
109 I<Please see the included demo called "website" for this file.>
110  
111 =head2 Content of settings file "usage_prefs.pl", tracking as much as possible
112  
113 my $rh_preferences = {
114 email_logs => 1, # do we want to be sent daily reports?
115 fn_dcm => 'date_counts_mailed.txt', # our lock file to track mailings
116 mailing => [ # keep different types of reports in own emails
117 {
118 filenames => 'env.txt',
119 subject_unique => ' -- usage (env) to ',
120 }, {
121 filenames => 'site_vrp.txt',
122 subject_unique => ' -- usage (page views) to ',
123 }, {
124 filenames => 'redirect_urls.txt',
125 subject_unique => ' -- usage (external) to ',
126 }, {
127 filenames => [qw(
128 ref_urls.txt ref_se_urls.txt
129 ref_se_keywords.txt ref_discards.txt
130 )],
131 subject_unique => ' -- usage (references) to ',
132 erase_files => 1, # start over listing each day
133 },
134 ],
135 env => { # what misc info do we want to know (low value distrib)
136 filename => 'env.txt',
137 var_list => [qw(
138 DOCUMENT_ROOT GATEWAY_INTERFACE HTTP_CONNECTION HTTP_HOST
139 REQUEST_METHOD SCRIPT_FILENAME SCRIPT_NAME SERVER_ADMIN
140 SERVER_NAME SERVER_PORT SERVER_PROTOCOL SERVER_SOFTWARE
141 )],
142 },
143 site => { # which pages on our own site are viewed?
144 filename => 'site_vrp.txt',
145 },
146 redirect => { # which of our external links are followed?
147 filename => 'redirect_urls.txt',
148 },
149 referrer => { # what sites are referring to us?
150 filename => 'ref_urls.txt', # normal websites go here
151 fn_search => 'ref_se_urls.txt', # search engines go here
152 fn_keywords => 'ref_se_keywords.txt', # their keywords go here
153 fn_discards => 'ref_discards.txt', # uris we filter out
154 discards => [qw( # filter uri's we want to ignore
155 ^(?!http://)
156 deja
157 mail
158 )],
159 search_engines => { # match domain with query param holding keywords
160 alltheweb => 'query', # AllTheWeb
161 altavista => 'q', # Altavista
162 'aj.com' => 'ask', # Ask Jeeves
163 aol => 'query', # America Online
164 'ask.com' => 'ask', # Ask Jeeves
165 askjeeves => 'ask', # Ask Jeeves
166 'c4.com' => 'searchtext', # C4
167 'cs.com' => 'sterm', # CompuServe
168 dmoz => 'search', # Mozilla Open Directory
169 dogpile => 'q', # DogPile
170 excite => 's', # Excite
171 google => 'q', # Google
172 'goto.com' => 'keywords', # GoTo.com, Inc
173 'icq.com' => 'query', # ICQ
174 infogrid => 'search', # InfoGrid
175 intelliseek => 'queryterm', # "Infrastructure For Intelligent Portals"
176 iwon => 'searchfor', # I Won
177 looksmart => 'key', # LookSmart
178 lycos => 'query', # Lycos
179 mamma => 'query', # "Mother of Search Engines"
180 metacrawler => 'general', # MetaCrawler
181 msn => ['q','mt'], # Microsoft
182 nbci => 'keyword', # NBCi
183 netscape => 'search', # Netscape
184 ninemsn => 'q', # nine msn
185 northernlight => 'qr', # Northern Light Search
186 'search.com' => 'q', # CNET
187 'searchalot' => 'search', # SearchALot
188 snap => 'keyword', # Microsoft
189 webcrawler => 'search', # Webcrawler
190 yahoo => 'p', # Yahoo
191 },
192 },
193 };
194  
195 =head1 DESCRIPTION
196  
197 This Perl 5 object class is part of a demonstration of CGI::Portable in use.
198 It is one of a set of "application components" that takes its settings and user
199 input through CGI::Portable and uses that class to send its user output.
200 This demo module set can be used together to implement a web site complete with
201 static html pages, e-mail forms, guest books, segmented text document display,
202 usage tracking, and url-forwarding. Of course, true to the intent of
203 CGI::Portable, each of the modules in this demo set can be used independantly
204 of the others.
205  
206 =head1 SYNTAX
207  
208 This class does not export any functions or methods, so you need to call them
209 using object notation. This means using B<Class-E<gt>function()> for functions
210 and B<$object-E<gt>method()> for methods. If you are inheriting this class for
211 your own modules, then that often means something like B<$self-E<gt>method()>.
212  
213 =head1 PUBLIC FUNCTIONS AND METHODS
214  
215 =head2 main( GLOBALS )
216  
217 You invoke this method to run the application component that is encapsulated by
218 this class. The required argument GLOBALS is an CGI::Portable object that
219 you have previously configured to hold the instance settings and user input for
220 this class. When this method returns then the encapsulated application will
221 have finished and you can get its user output from the CGI::Portable object.
222  
223 =head1 PREFERENCES HANDLED BY THIS MODULE
224  
225 I<This POD is coming when I get the time to write it.>
226  
227 =cut
228  
229 ######################################################################
230  
231 # Names of properties for objects of this class are declared here:
232 1 my $KEY_SITE_GLOBALS = 'site_globals'; # hold global site values
233  
234 # Keys for items in site page preferences:
235  
236 1 my $PKEY_TOKEN_TOTAL = 'token_total'; # token counts number of file updates
237 1 my $PKEY_TOKEN_NIL = 'token_nil'; # token counts number of '' values
238 1 my $PKEY_EMAIL_LOGS = 'email_logs'; # true if logs get emailed
239 1 my $PKEY_FN_DCM = 'fn_dcm'; # filename for "date counts mailed" record
240 1 my $PKEY_MAILING = 'mailing'; # array of hashes
241 1 my $PKEY_LOG_ENV = 'env'; # misc env variables go in here
242 # Generally only ENVs with a low distribution of values go here.
243 1 my $PKEY_LOG_SITE = 'site'; # pages within this site (vrp) go in here
244 1 my $PKEY_LOG_REDIRECT = 'redirect'; # urls we redirect to go in here
245 1 my $PKEY_LOG_REFERRER = 'referrer'; # urls that refer to us go in here
246 # note that urls for common search engines are stored separately
247 # from those that aren't
248  
249 # Keys for elements in $PKEY_MAILING hash:
250 1 my $MKEY_FILENAMES = 'filenames'; # list of filenames to include in mailing
251 1 my $MKEY_ERASE_FILES = 'erase_files'; # if true, then erase files afterwards
252 1 my $MKEY_SUBJECT_UNIQUE = 'subject_unique'; # unique part of e-mail subject
253 # this text would go following site title and before today's date in subject
254  
255 # Keys in common for $KEY_LOG_* hashes:
256 1 my $LKEY_FILENAME = 'filename';
257  
258 # Keys used only in $KEY_LOG_ENV hash:
259 1 my $EKEY_VAR_LIST = 'var_list'; # name misc env variables to watch
260  
261 # Keys used only in $KEY_LOG_SITE hash:
262 1 my $SKEY_TOKEN_REDIRECT = 'token_redirect';
263  
264 # Keys used only in $KEY_LOG_REFERRER hash:
265 1 my $RKEY_FN_SEARCH = 'fn_search'; # urls for ref common search engines
266 # note that search engine query strings are removed here, go next
267 1 my $RKEY_FN_KEYWORDS = 'fn_keywords'; # keywords used in sea eng ref url
268 # note that only se are counted, normal site kw kept with their urls
269 1 my $RKEY_FN_DISCARDS = 'fn_discards'; # urls such as news:// go only here
270 1 my $RKEY_TOKEN_REF_SELF = 'token_ref_self'; # indicates referer was same site
271 1 my $RKEY_TOKEN_REF_OTHER = 'token_ref_other'; # ref not self but in other file
272 1 my $RKEY_DISCARDS = 'discards'; # if ref url matches these, filter junk
273 1 my $RKEY_SEARCH_ENGINES = 'search_engines'; # search engines and kw param names
274  
275 ######################################################################
276  
277 0 ▶sub main {
Subroutine main: not called CC=3 SCAR=24.8
Pod documented
278 0 my ($class, $globals) = @_;
279 0 ▶ my $self = bless( {}, ref($class) || $class );
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
280  
281 0 ▶ UNIVERSAL::isa( $globals, 'CGI::Portable' ) or
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($globals, "CGI::Portable") or die "initializer is not a valid CGI::Portable object" 0 0 0
282 die "initializer is not a valid CGI::Portable object";
283  
284 0 $self->{$KEY_SITE_GLOBALS} = $globals;
285 0 $self->main_dispatch();
286 }
287  
288 ######################################################################
289  
290 0 ▶sub main_dispatch {
Subroutine main_dispatch: not called CC=3 SCAR=24.8
Pod undocumented
291 0 my $self = shift( @_ );
292 0 my $globals = $self->{$KEY_SITE_GLOBALS};
293 0 my $rh_prefs = $globals->get_prefs_ref();
294  
295 0 ▶ $rh_prefs->{$PKEY_TOKEN_TOTAL} ||= '__total__';
Condition0%0/2
$rh_prefs->{$PKEY_TOKEN_TOTAL} ||= "__total__"
l!l
00
MC/DC0%0/1
$rh_prefs->{$PKEY_TOKEN_TOTAL} ||= "__total__"
$rh_prefs->{$PKEY_TOKEN_TOTAL}
Truth table0%0/2
A
A= $rh_prefs->{$PKEY_TOKEN_TOTAL}
Aresult
11
00
296 0 ▶ $rh_prefs->{$PKEY_TOKEN_NIL} ||= '__nil__';
Condition0%0/2
$rh_prefs->{$PKEY_TOKEN_NIL} ||= "__nil__"
l!l
00
MC/DC0%0/1
$rh_prefs->{$PKEY_TOKEN_NIL} ||= "__nil__"
$rh_prefs->{$PKEY_TOKEN_NIL}
Truth table0%0/2
A
A= $rh_prefs->{$PKEY_TOKEN_NIL}
Aresult
11
00
297  
298 0 $self->email_and_reset_counts_if_new_day();
299
300 0 $self->update_env_counts();
301 0 $self->update_site_vrp_counts();
302 0 $self->update_redirect_counts();
303 0 $self->update_referrer_counts();
304
305 # Note that we don't presently print hit counts to the webpage.
306 # But that'll likely be added later, along with web usage reports.
307 }
308  
309 ######################################################################
310  
311 0 ▶sub email_and_reset_counts_if_new_day {
Subroutine email_and_reset_counts_if_new_day: not called CC=15 SCAR=54.8
Pod undocumented
312 0 my $self = shift( @_ );
313 0 my $globals = $self->{$KEY_SITE_GLOBALS};
314 0 my $rh_prefs = $globals->get_prefs_ref();
315  
316 0 ▶ $rh_prefs->{$PKEY_EMAIL_LOGS} or return( 1 );
Branch: 1 branch
BranchTrueFalseTotal
$rh_prefs->{$PKEY_EMAIL_LOGS} or return 1 0 0 0
317  
318 my $dcm_file =
319 0 DemoUsage::CountFile->new( $globals, $rh_prefs->{$PKEY_FN_DCM} );
320 0 ▶ $dcm_file->open_and_lock( 1 ) or return( undef );
Branch: 1 branch
BranchTrueFalseTotal
$dcm_file->open_and_lock(1) or return undef 0 0 0
321 0 $dcm_file->read_all_records();
322 0 ▶ if( $dcm_file->key_was_incremented_today(
Branch: 1 branch
BranchTrueFalseTotal
if ($dcm_file->key_was_incremented_today($rh_prefs->{$PKEY_TOKEN_TOTAL})) 0 0 0
323 $rh_prefs->{$PKEY_TOKEN_TOTAL} ) ) {
324 0 $dcm_file->unlock_and_close();
325 0 return( 1 );
326 }
327 0 $dcm_file->key_increment( $rh_prefs->{$PKEY_TOKEN_TOTAL} );
328 0 $dcm_file->write_all_records();
329 0 $dcm_file->unlock_and_close();
330  
331 0 my $ra_mail_prefs = $rh_prefs->{$PKEY_MAILING};
332 0 ▶ ref( $ra_mail_prefs ) eq 'ARRAY' or $ra_mail_prefs = [$ra_mail_prefs];
Branch: 1 branch
BranchTrueFalseTotal
ref $ra_mail_prefs eq "ARRAY" or $ra_mail_prefs = [$ra_mail_prefs] 0 0 0
333  
334 0 foreach my $rh_mail_pref (@{$ra_mail_prefs}) {
335 0 ▶ ref( $rh_mail_pref ) eq 'HASH' or next;
Branch: 1 branch
BranchTrueFalseTotal
ref $rh_mail_pref eq "HASH" or next 0 0 0
336  
337 0 ▶ my $ra_filenames = $rh_mail_pref->{$MKEY_FILENAMES} || [];
Condition0%0/2
$rh_mail_pref->{$MKEY_FILENAMES} || []
l!l
00
MC/DC0%0/1
$rh_mail_pref->{$MKEY_FILENAMES} || []
$rh_mail_pref->{$MKEY_FILENAMES}
Truth table0%0/2
A
A= $rh_mail_pref->{$MKEY_FILENAMES}
Aresult
11
00
338 0 ▶ ref( $ra_filenames ) eq 'ARRAY' or $ra_filenames = [$ra_filenames];
Branch: 1 branch
BranchTrueFalseTotal
ref $ra_filenames eq "ARRAY" or $ra_filenames = [$ra_filenames] 0 0 0
339 0 my $erase_files = $rh_mail_pref->{$MKEY_ERASE_FILES};
340  
341 0 my @mail_body = ();
342  
343 0 foreach my $filename (@{$ra_filenames}) {
344 0 ▶ $filename or next;
Branch: 1 branch
BranchTrueFalseTotal
$filename or next 0 0 0
345 0 my $count_file =
346 DemoUsage::CountFile->new( $globals, $filename );
347 0 ▶ $count_file->open_and_lock( 1 ) or do {
Branch: 1 branch
BranchTrueFalseTotal
$count_file->open_and_lock(1) or do { push @mail_body, "\n\n" . $globals->get_error . "\n"; next } 0 0 0
348 0 push( @mail_body, "\n\n".$globals->get_error()."\n" );
349 0 next;
350 };
351 0 $count_file->read_all_records();
352 0 push( @mail_body, "\n\ncontent of '$filename':\n\n" );
353 0 push( @mail_body, $count_file->get_sorted_file_content() );
354 0 ▶ if( $erase_files ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($erase_files) { } 0 0 0
355 0 $count_file->delete_all_keys();
356 } else {
357 0 $count_file->set_all_day_counts_to_zero();
358 }
359 0 $count_file->write_all_records();
360 0 $count_file->unlock_and_close();
361 }
362  
363 0 my ($today_str) = ($self->today_date_utc() =~ m/^(\S+)/ );
364 0 my $subject_unique = $rh_mail_pref->{$MKEY_SUBJECT_UNIQUE};
365 0 ▶ defined( $subject_unique) or $subject_unique = ' -- usage to ';
Branch: 1 branch
BranchTrueFalseTotal
defined $subject_unique or $subject_unique = " -- usage to " 0 0 0
366  
367 0 my $err_msg = $self->send_email_message(
368 $globals->default_maintainer_name(),
369 $globals->default_maintainer_email_address(),
370 $globals->default_maintainer_name(),
371 $globals->default_maintainer_email_address(),
372 $globals->default_application_title().$subject_unique.$today_str,
373 join( '', @mail_body ),
374 <<__endquote,
375 This is a daily copy of the site usage count logs.
376 The first visitor activity on $today_str has just occurred.
377 __endquote
378 );
379  
380 0 ▶ if( $err_msg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err_msg) 0 0 0
381 0 $globals->add_error( "can't e-mail usage counts: $err_msg" );
382 }
383 }
384 }
385  
386 ######################################################################
387  
388 0 ▶sub update_env_counts {
Subroutine update_env_counts: not called CC=4 SCAR=30.0
Pod undocumented
389 0 my $self = shift( @_ );
390 0 my $globals = $self->{$KEY_SITE_GLOBALS};
391 0 my $rh_prefs = $globals->get_prefs_ref();
392
393 0 my $rh_log_prefs = $rh_prefs->{$PKEY_LOG_ENV};
394 0 ▶ ref( $rh_log_prefs ) eq 'HASH' or return( 0 );
Branch: 1 branch
BranchTrueFalseTotal
ref $rh_log_prefs eq "HASH" or return 0 0 0 0
395
396 0 ▶ my $filename = $rh_log_prefs->{$LKEY_FILENAME} or return( 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $filename = $rh_log_prefs->{$LKEY_FILENAME} or return 0 0 0 0
397 0 my $ra_var_list = $rh_log_prefs->{$EKEY_VAR_LIST};
398 0 ▶ ref( $ra_var_list ) eq 'ARRAY' or $ra_var_list = [$ra_var_list];
Branch: 1 branch
BranchTrueFalseTotal
ref $ra_var_list eq "ARRAY" or $ra_var_list = [$ra_var_list] 0 0 0
399
400 # save miscellaneous low-distribution environment vars
401 $self->update_one_count_file( $filename,
402 0 (map { "\$ENV{$_} = \"$ENV{$_}\"" } @{$ra_var_list}) );
403 }
404  
405 ######################################################################
406  
407 0 ▶sub update_site_vrp_counts {
Subroutine update_site_vrp_counts: not called CC=5 SCAR=34.0
Pod undocumented
408 0 my $self = shift( @_ );
409 0 my $globals = $self->{$KEY_SITE_GLOBALS};
410 0 my $rh_prefs = $globals->get_prefs_ref();
411
412 0 my $rh_log_prefs = $rh_prefs->{$PKEY_LOG_SITE};
413 0 ▶ ref( $rh_log_prefs ) eq 'HASH' or return( 0 );
Branch: 1 branch
BranchTrueFalseTotal
ref $rh_log_prefs eq "HASH" or return 0 0 0 0
414
415 0 ▶ my $filename = $rh_log_prefs->{$LKEY_FILENAME} or return( 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $filename = $rh_log_prefs->{$LKEY_FILENAME} or return 0 0 0 0
416 0 ▶ my $t_rd = $rh_log_prefs->{$SKEY_TOKEN_REDIRECT} || '__external_url__';
Condition0%0/2
$rh_log_prefs->{$SKEY_TOKEN_REDIRECT} || '__external_url__'
l!l
00
MC/DC0%0/1
$rh_log_prefs->{$SKEY_TOKEN_REDIRECT} || '__external_url__'
$rh_log_prefs->{$SKEY_TOKEN_REDIRECT}
Truth table0%0/2
A
A= $rh_log_prefs->{$SKEY_TOKEN_REDIRECT}
Aresult
11
00
417
418 # save which page within this site was hit
419 0 ▶ $self->update_one_count_file( $filename,
Branch: 1 branch
BranchTrueFalseTotal
$globals->http_redirect_url ? : 0 0 0
420 $globals->user_path_string(),
421 $globals->http_redirect_url() ? $t_rd : () );
422 }
423  
424 ######################################################################
425  
426 0 ▶sub update_redirect_counts {
Subroutine update_redirect_counts: not called CC=3 SCAR=24.8
Pod undocumented
427 0 my $self = shift( @_ );
428 0 my $globals = $self->{$KEY_SITE_GLOBALS};
429 0 my $rh_prefs = $globals->get_prefs_ref();
430
431 0 my $rh_log_prefs = $rh_prefs->{$PKEY_LOG_REDIRECT};
432 0 ▶ ref( $rh_log_prefs ) eq 'HASH' or return( 0 );
Branch: 1 branch
BranchTrueFalseTotal
ref $rh_log_prefs eq "HASH" or return 0 0 0 0
433
434 0 ▶ my $filename = $rh_log_prefs->{$LKEY_FILENAME} or return( 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $filename = $rh_log_prefs->{$LKEY_FILENAME} or return 0 0 0 0
435
436 # save which url this site referred the visitor to, if any
437 0 $self->update_one_count_file( $filename, $globals->http_redirect_url() );
438 }
439  
440 ######################################################################
441  
442 0 ▶sub update_referrer_counts {
Subroutine update_referrer_counts: not called CC=20 SCAR=60.4
Pod undocumented
443 0 my $self = shift( @_ );
444 0 my $globals = $self->{$KEY_SITE_GLOBALS};
445 0 my $rh_prefs = $globals->get_prefs_ref();
446
447 0 my $rh_log_prefs = $rh_prefs->{$PKEY_LOG_REFERRER};
448 0 ▶ ref( $rh_log_prefs ) eq 'HASH' or return( 0 );
Branch: 1 branch
BranchTrueFalseTotal
ref $rh_log_prefs eq "HASH" or return 0 0 0 0
449
450 0 my $fn_normal = $rh_log_prefs->{$LKEY_FILENAME};
451 0 my $fn_search = $rh_log_prefs->{$RKEY_FN_SEARCH};
452 0 my $fn_keywords = $rh_log_prefs->{$RKEY_FN_KEYWORDS};
453 0 my $fn_discards = $rh_log_prefs->{$RKEY_FN_DISCARDS};
454
455 0 ▶ my $t_rfs = $rh_log_prefs->{$RKEY_TOKEN_REF_SELF} || '__self_reference__';
Condition0%0/2
$rh_log_prefs->{$RKEY_TOKEN_REF_SELF} || '__self_reference__'
l!l
00
MC/DC0%0/1
$rh_log_prefs->{$RKEY_TOKEN_REF_SELF} || '__self_reference__'
$rh_log_prefs->{$RKEY_TOKEN_REF_SELF}
Truth table0%0/2
A
A= $rh_log_prefs->{$RKEY_TOKEN_REF_SELF}
Aresult
11
00
456 0 ▶ my $t_rfo = $rh_log_prefs->{$RKEY_TOKEN_REF_OTHER} || '__other_reference__';
Condition0%0/2
$rh_log_prefs->{$RKEY_TOKEN_REF_OTHER} || '__other_reference__'
l!l
00
MC/DC0%0/1
$rh_log_prefs->{$RKEY_TOKEN_REF_OTHER} || '__other_reference__'
$rh_log_prefs->{$RKEY_TOKEN_REF_OTHER}
Truth table0%0/2
A
A= $rh_log_prefs->{$RKEY_TOKEN_REF_OTHER}
Aresult
11
00
457
458 0 ▶ my $ra_discards = $rh_log_prefs->{$RKEY_DISCARDS} || [];
Condition0%0/2
$rh_log_prefs->{$RKEY_DISCARDS} || []
l!l
00
MC/DC0%0/1
$rh_log_prefs->{$RKEY_DISCARDS} || []
$rh_log_prefs->{$RKEY_DISCARDS}
Truth table0%0/2
A
A= $rh_log_prefs->{$RKEY_DISCARDS}
Aresult
11
00
459 0 ▶ ref( $ra_discards ) eq 'ARRAY' or $ra_discards = [$ra_discards];
Branch: 1 branch
BranchTrueFalseTotal
ref $ra_discards eq "ARRAY" or $ra_discards = [$ra_discards] 0 0 0
460
461 0 my $rh_engines = $rh_log_prefs->{$RKEY_SEARCH_ENGINES};
462 0 ▶ ref( $rh_engines ) eq 'HASH' or $rh_engines = {};
Branch: 1 branch
BranchTrueFalseTotal
ref $rh_engines eq "HASH" or $rh_engines = {} 0 0 0
463
464 # save which url had referred visitors to this site
465 0 my (@ref_norm, @ref_sear, @ref_keyw, @ref_disc);
466  
467 SWITCH: {
468 0 my $referer = $globals->referer();
469 0 my ($ref_filename, $query) = split( /\?/, $referer, 2 );
470 0 $ref_filename =~ s|/$||; # lose trailing "/"s
471 0 ▶ $referer = ($query =~ /[a-zA-Z0-9]/) ?
Branch: 1 branch
BranchTrueFalseTotal
$query =~ /[a-zA-Z0-9]/ ? : 0 0 0
472 "$ref_filename?$query" : $ref_filename;
473 0 $ref_filename =~ m|^http://([^/]+)(.*)|;
474 0 my ($domain, $path) = ($1, $2);
475
476 # first check if visitor is moving within our own site
477 0 my $site_url = $globals->url_base();
478 0 ▶ if( $ref_filename =~ m|$site_url|i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_filename =~ /$site_url/i) 0 0 0
479 0 push( @ref_norm, $t_rfs );
480 0 push( @ref_sear, $t_rfs );
481 0 push( @ref_keyw, $t_rfs );
482 0 push( @ref_disc, $t_rfs );
483 0 last SWITCH;
484 }
485  
486 # else check if visitor came from checking an e-mail online
487 0 foreach my $ident (@{$ra_discards}) {
488 0 ▶ if( $ref_filename =~ m|$ident|i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_filename =~ /$ident/i) 0 0 0
489 0 push( @ref_norm, $t_rfo );
490 0 push( @ref_sear, $t_rfo );
491 0 push( @ref_keyw, $t_rfo );
492 0 push( @ref_disc, $referer );
493 0 last SWITCH;
494 }
495 }
496
497 # else check if the referring domain is a search engine
498 0 foreach my $dom_frag (keys %{$rh_engines}) {
499 0 ▶ if( ".$domain." =~ m|[/\.]$dom_frag\.|i ) { # CHANGED THIS LINE 0-43
Branch: 1 branch
BranchTrueFalseTotal
if ((".$domain.") =~ m[[/\.]$dom_frag\.]i) 0 0 0
500 0 my $se_query = CGI::MultiValuedHash->new( 1, $query );
501 0 my @se_keywords;
502
503 0 my $kwpn = $rh_engines->{$dom_frag};
504 0 ▶ my @kwpn = ref($kwpn) eq 'ARRAY' ? @{$kwpn} : $kwpn;
Branch: 1 branch
BranchTrueFalseTotal
ref $kwpn eq 'ARRAY' ? : 0 0 0
505 0 foreach my $query_param (@kwpn) {
506 0 push( @se_keywords, split( /\s+/,
507 $se_query->fetch_value( $query_param ) ) );
508 }
509  
510 0 foreach my $kw (@se_keywords) {
511 0 $kw =~ s/^[^a-zA-Z0-9]+//; # remove framing junk
512 0 $kw =~ s/[^a-zA-Z0-9]+$//;
513 0 $kw = lc( $kw ); # ADDED THIS LINE 0-43
514 }
515  
516 # save both the file name and the search words used
517 0 push( @ref_norm, $t_rfo );
518 0 push( @ref_sear, $ref_filename );
519 0 push( @ref_keyw, @se_keywords );
520 0 push( @ref_disc, $t_rfo );
521 0 last SWITCH;
522 }
523 }
524  
525 # otherwise, referer is probably a normal web site
526 0 push( @ref_norm, $referer );
527 0 push( @ref_sear, $t_rfo );
528 0 push( @ref_keyw, $t_rfo );
529 0 push( @ref_disc, $t_rfo );
530 }
531  
532 0 ▶ $fn_normal and $self->update_one_count_file( $fn_normal, @ref_norm );
Branch: 1 branch
BranchTrueFalseTotal
$fn_normal and $self->update_one_count_file($fn_normal, @ref_norm) 0 0 0
533 0 ▶ $fn_search and $self->update_one_count_file( $fn_search, @ref_sear );
Branch: 1 branch
BranchTrueFalseTotal
$fn_search and $self->update_one_count_file($fn_search, @ref_sear) 0 0 0
534 0 ▶ $fn_keywords and $self->update_one_count_file( $fn_keywords, @ref_keyw );
Branch: 1 branch
BranchTrueFalseTotal
$fn_keywords and $self->update_one_count_file($fn_keywords, @ref_keyw) 0 0 0
535 0 ▶ $fn_discards and $self->update_one_count_file( $fn_discards, @ref_disc );
Branch: 1 branch
BranchTrueFalseTotal
$fn_discards and $self->update_one_count_file($fn_discards, @ref_disc) 0 0 0
536 }
537  
538 ######################################################################
539  
540 0 ▶sub update_one_count_file {
Subroutine update_one_count_file: not called CC=4 SCAR=30.0
Pod undocumented
541 0 my ($self, $filename, @keys_to_inc) = @_;
542 0 my $globals = $self->{$KEY_SITE_GLOBALS};
543 0 my $rh_prefs = $globals->get_prefs_ref();
544  
545 0 push( @keys_to_inc, $rh_prefs->{$PKEY_TOKEN_TOTAL} );
546  
547 0 my $count_file =
548 DemoUsage::CountFile->new( $globals, $filename );
549 0 ▶ $count_file->open_and_lock( 1 ) or return( undef );
Branch: 1 branch
BranchTrueFalseTotal
$count_file->open_and_lock(1) or return undef 0 0 0
550 0 $count_file->read_all_records();
551  
552 0 foreach my $key (@keys_to_inc) {
553 0 ▶ $key eq '' and $key = $rh_prefs->{$PKEY_TOKEN_NIL};
Branch: 1 branch
BranchTrueFalseTotal
$key eq "" and $key = $rh_prefs->{$PKEY_TOKEN_NIL} 0 0 0
554 0 $count_file->key_increment( $key );
555 }
556  
557 0 $count_file->write_all_records();
558 0 $count_file->unlock_and_close();
559 }
560  
561 ######################################################################
562  
563 0 ▶sub send_email_message {
Subroutine send_email_message: not called CC=9 SCAR=45.0
Pod undocumented
564 0 my ($self, $to_name, $to_email, $from_name, $from_email,
565 $subject, $body, $body_head_addition) = @_;
566 0 my $globals = $self->{$KEY_SITE_GLOBALS};
567  
568 0 my $EMAIL_HEADER_STRIP_PATTERN = '[,<>()"\'\n]'; #for names and addys
569 0 $to_name =~ s/$EMAIL_HEADER_STRIP_PATTERN//g;
570 0 $to_email =~ s/$EMAIL_HEADER_STRIP_PATTERN//g;
571 0 $from_name =~ s/$EMAIL_HEADER_STRIP_PATTERN//g;
572 0 $from_email =~ s/$EMAIL_HEADER_STRIP_PATTERN//g;
573 0 ▶ $globals->is_debug() and $subject .= " -- debug";
Branch: 1 branch
BranchTrueFalseTotal
$globals->is_debug and $subject .= ' -- debug' 0 0 0
574
575 0 my $body_header = <<__endquote.
576 --------------------------------------------------
577 0 This e-mail was sent at @{[$self->today_date_utc()]}
578 0 by the web site "@{[$globals->default_application_title()]}",
579 0 ▶which is located at "@{[$globals->url_base()]}".
Branch: 1 branch
BranchTrueFalseTotal
$globals->is_debug ? : 0 0 0
580 __endquote
581 $body_head_addition.
582 ($globals->is_debug() ? "Debugging is currently turned on.\n" :
583 '').<<__endquote;
584 --------------------------------------------------
585 __endquote
586  
587 0 my $body_footer = <<__endquote;
588  
589  
590 --------------------------------------------------
591 END OF MESSAGE
592 __endquote
593
594 0 my $host = $globals->default_smtp_host();
595 0 my $timeout = $globals->default_smtp_timeout();
596 0 my $error_msg = '';
597  
598 TRY: {
599 0 my $smtp;
600  
601 0 eval { require Net::SMTP; };
602 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
603 0 $error_msg = "can't open program module 'Net::SMTP'";
604 0 last TRY;
605 }
606
607 0 ▶ unless( $smtp = Net::SMTP->new( $host, Timeout => $timeout ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($smtp = "Net::SMTP"->new($host, "Timeout", $timeout)) 0 0 0
608 0 $error_msg = "can't connect to smtp host: $host";
609 0 last TRY;
610 }
611  
612 0 ▶ unless( $smtp->verify( $from_email ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($smtp->verify($from_email)) 0 0 0
613 0 $error_msg = "invalid address: @{[$smtp->message()]}";
614 0 last TRY;
615 }
616  
617 0 ▶ unless( $smtp->verify( $to_email ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($smtp->verify($to_email)) 0 0 0
618 0 $error_msg = "invalid address: @{[$smtp->message()]}";
619 0 last TRY;
620 }
621  
622 0 ▶ unless( $smtp->mail( "$from_name <$from_email>" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($smtp->mail("$from_name <$from_email>")) 0 0 0
623 0 $error_msg = "from: @{[$smtp->message()]}";
624 0 last TRY;
625 }
626  
627 0 ▶ unless( $smtp->to( "$to_name <$to_email>" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($smtp->to("$to_name <$to_email>")) 0 0 0
628 0 $error_msg = "to: @{[$smtp->message()]}";
629 0 last TRY;
630 }
631  
632 0 $smtp->data( <<__endquote );
633 From: $from_name <$from_email>
634 To: $to_name <$to_email>
635 Subject: $subject
636 Content-Type: text/plain; charset=us-ascii
637  
638 $body_header
639 $body
640 $body_footer
641 __endquote
642  
643 0 $smtp->quit();
644 }
645
646 0 return( $error_msg );
647 }
648  
649 ######################################################################
650  
651 0 ▶sub today_date_utc {
Subroutine today_date_utc: not called CC=1 SCAR=6.9
Pod undocumented
652 0 my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(time);
653 0 $year += 1900; # year counts from 1900 AD otherwise
654 0 $mon += 1; # ensure January is 1, not 0
655 0 my @parts = ($year, $mon, $mday, $hour, $min, $sec);
656 0 return( sprintf( "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d UTC", @parts ) );
657 }
658  
659 ######################################################################
660  
661 package DemoUsage::CountFile;
662 1 ▶use Fcntl qw(:DEFAULT :flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
663 1 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
664  
665 # Names of properties for objects of this class are declared here:
666 #my $KEY_SITE_GLOBALS = 'site_globals'; # hold global site values
667 1 my $KEY_FILEHANDLE = 'filehandle'; # stores the filehandle
668 1 my $KEY_FILENAME = 'filename'; # external name of this file
669 1 my $KEY_FILE_LINES = 'file_lines'; # hold content of file when open
670  
671 # Indexes into array of record fields:
672 1 my $IND_KEY_TO_COUNT = 0; # name of what we are counting
673 1 my $IND_DATE_ACC_FIRST = 1; # date of first access
674 1 my $IND_DATE_ACC_LAST = 2; # date of last access
675 1 my $IND_COUNT_ACC_ALL = 3; # count of accesses btwn first and last
676 1 my $IND_COUNT_ACC_DAY = 4; # count of accesses today only
677  
678 # Constant values used in this class go here:
679 1 my $DELIM_RECORDS = "\n"; # this is standard
680 1 my $DELIM_FIELDS = "\t"; # this is a standard
681 1 my $BYTES_TO_KILL = '[\00-\31]'; # remove all control characters
682  
683 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
684 0 my $class = shift( @_ );
685 0 ▶ my $self = bless( {}, ref($class) || $class );
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
686 0 $self->{$KEY_SITE_GLOBALS} = shift( @_ );
687 0 $self->{$KEY_FILEHANDLE} = gensym;
688 0 $self->{$KEY_FILENAME} = shift( @_ );
689 0 return( $self );
690 }
691  
692 0 ▶sub open_and_lock {
Subroutine open_and_lock: not called CC=5 SCAR=34.0
693 0 my ($self, $read_and_write) = @_;
694 0 my $globals = $self->{$KEY_SITE_GLOBALS};
695 0 my $fh = $self->{$KEY_FILEHANDLE};
696 0 my $filename = $self->{$KEY_FILENAME};
697
698 0 my $physical_path = $globals->physical_filename( $filename );
699 0 ▶ my $flags = $read_and_write ? O_RDWR|O_CREAT : O_RDONLY;
Branch: 1 branch
BranchTrueFalseTotal
$read_and_write ? : 0 0 0
700 0 my $perms = 0666;
701  
702 0 $globals->add_no_error();
703  
704 0 ▶ sysopen( $fh, $physical_path, $flags, $perms ) or do {
Branch: 1 branch
BranchTrueFalseTotal
sysopen $fh, $physical_path, $flags, $perms or do { $globals->add_virtual_filename_error("open", $filename); return undef } 0 0 0
705 0 $globals->add_virtual_filename_error( "open", $filename );
706 0 return( undef );
707 };
708  
709 0 ▶ flock( $fh, $read_and_write ? LOCK_EX : LOCK_SH ) or do {
Branch: 2 branches
BranchTrueFalseTotal
flock $fh, $read_and_write ? 2 : 1 or do { $globals->add_virtual_filename_error("lock", $filename); return undef } 0 0 0
$read_and_write ? : 0 0 0
710 0 $globals->add_virtual_filename_error( "lock", $filename );
711 0 return( undef );
712 };
713  
714 0 return( 1 );
715 }
716  
717 0 ▶sub unlock_and_close {
Subroutine unlock_and_close: not called CC=3 SCAR=24.8
718 0 my ($self) = @_;
719 0 my $globals = $self->{$KEY_SITE_GLOBALS};
720 0 my $fh = $self->{$KEY_FILEHANDLE};
721 0 my $filename = $self->{$KEY_FILENAME};
722
723 0 $globals->add_no_error();
724  
725 0 ▶ flock( $fh, LOCK_UN ) or do {
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 8 or do { $globals->add_virtual_filename_error("unlock", $filename); return undef } 0 0 0
726 0 $globals->add_virtual_filename_error( "unlock", $filename );
727 0 return( undef );
728 };
729  
730 0 ▶ close( $fh ) or do {
Branch: 1 branch
BranchTrueFalseTotal
close $fh or do { $globals->add_virtual_filename_error("close", $filename); return undef } 0 0 0
731 0 $globals->add_virtual_filename_error( "close", $filename );
732 0 return( undef );
733 };
734  
735 0 return( 1 );
736 }
737  
738 0 ▶sub read_all_records {
Subroutine read_all_records: not called CC=4 SCAR=30.0
739 0 my ($self) = @_;
740 0 my $globals = $self->{$KEY_SITE_GLOBALS};
741 0 my $fh = $self->{$KEY_FILEHANDLE};
742 0 my $filename = $self->{$KEY_FILENAME};
743
744 0 $globals->add_no_error();
745  
746 0 ▶ seek( $fh, 0, 0 ) or do {
Branch: 1 branch
BranchTrueFalseTotal
seek $fh, 0, 0 or do { $globals->add_virtual_filename_error("seek start of", $filename); return undef } 0 0 0
747 0 $globals->add_virtual_filename_error( "seek start of", $filename );
748 0 return( undef );
749 };
750  
751 0 local $/ = undef;
752  
753 0 ▶ defined( my $file_content = <$fh> ) or do {
Branch: 1 branch
BranchTrueFalseTotal
defined(my $file_content = readline $fh) or do { $globals->add_virtual_filename_error("read records from", $filename); return undef } 0 0 0
754 0 $globals->add_virtual_filename_error( "read records from", $filename );
755 0 return( undef );
756 };
757
758 0 my @record_list = split( $DELIM_RECORDS, $file_content );
759 0 my %record_hash = ();
760
761 0 foreach my $record_str (@record_list) {
762 0 my $key = substr( $record_str, 0, index(
763 $record_str, $DELIM_FIELDS ) ); # faster then reg exp?
764 0 $record_hash{$key} = $record_str;
765 }
766  
767 0 $self->{$KEY_FILE_LINES} = \%record_hash;
768
769 0 return( 1 );
770 }
771  
772 0 ▶sub write_all_records {
Subroutine write_all_records: not called CC=4 SCAR=30.0
773 0 my ($self) = @_;
774 0 my $globals = $self->{$KEY_SITE_GLOBALS};
775 0 my $fh = $self->{$KEY_FILEHANDLE};
776 0 my $filename = $self->{$KEY_FILENAME};
777
778 0 my @record_list = values %{$self->{$KEY_FILE_LINES}};
779 0 my $file_content = join( $DELIM_RECORDS, @record_list );
780
781 0 $globals->add_no_error();
782  
783 0 ▶ seek( $fh, 0, 0 ) or do {
Branch: 1 branch
BranchTrueFalseTotal
seek $fh, 0, 0 or do { $globals->add_virtual_filename_error("seek start of", $filename); return undef } 0 0 0
784 0 $globals->add_virtual_filename_error( "seek start of", $filename );
785 0 return( undef );
786 };
787  
788 0 ▶ truncate( $fh, 0 ) or do {
Branch: 1 branch
BranchTrueFalseTotal
truncate $fh, 0 or do { $globals->add_virtual_filename_error("truncate to start of", $filename); return undef } 0 0 0
789 0 $globals->add_virtual_filename_error( "truncate to start of", $filename );
790 0 return( undef );
791 };
792  
793 0 local $\ = undef;
794  
795 0 ▶ print $fh "$file_content" or do {
Branch: 1 branch
BranchTrueFalseTotal
print $fh "$file_content" or do { $globals->add_virtual_filename_error("write records to", $filename); return undef } 0 0 0
796 0 $globals->add_virtual_filename_error( "write records to", $filename );
797 0 return( undef );
798 };
799
800 0 return( 1 );
801 }
802  
803 0 ▶sub key_increment {
Subroutine key_increment: not called CC=3 SCAR=24.8
804 0 my ($self, $key) = @_;
805 0 $key =~ s/$BYTES_TO_KILL//;
806 0 my @fields = split( $DELIM_FIELDS, $self->{$KEY_FILE_LINES}->{$key} );
807
808 0 my $today_str = $self->today_date_utc();
809  
810 0 $fields[$IND_KEY_TO_COUNT] = $key;
811 0 ▶ if( $fields[$IND_COUNT_ACC_ALL] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields[$IND_COUNT_ACC_ALL] == 0) 0 0 0
812 0 $fields[$IND_DATE_ACC_FIRST] = $today_str;
813 }
814 0 $fields[$IND_DATE_ACC_LAST] = $today_str;
815 0 $fields[$IND_COUNT_ACC_ALL]++;
816 0 $fields[$IND_COUNT_ACC_DAY]++; # call different method to reset
817  
818 0 $self->{$KEY_FILE_LINES}->{$key} = join( $DELIM_FIELDS, @fields );
819 0 ▶ return( wantarray ? @fields : \@fields );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
820 }
821  
822 0 ▶sub delete_all_keys {
Subroutine delete_all_keys: not called CC=1 SCAR=6.9
823 0 my ($self) = @_;
824 0 $self->{$KEY_FILE_LINES} = {};
825 }
826  
827 0 ▶sub key_was_incremented_today {
Subroutine key_was_incremented_today: not called CC=1 SCAR=6.9
828 0 my ($self, $key) = @_;
829 0 $key =~ s/$BYTES_TO_KILL//;
830 0 my @fields = split( $DELIM_FIELDS, $self->{$KEY_FILE_LINES}->{$key} );
831 0 my ($today) = ($self->today_date_utc() =~ m/^(\S+)/ );
832 0 my ($last_acc) = ($fields[$IND_DATE_ACC_LAST] =~ m/^(\S+)/ );
833 0 return( $last_acc eq $today );
834 }
835  
836 0 ▶sub set_all_day_counts_to_zero {
Subroutine set_all_day_counts_to_zero: not called CC=2 SCAR=17.9
837 0 my ($self) = @_;
838 0 my $rh_file_lines = $self->{$KEY_FILE_LINES};
839 0 foreach my $key (keys %{$rh_file_lines}) {
840 0 my @fields = split( $DELIM_FIELDS, $rh_file_lines->{$key} );
841 0 $fields[$IND_COUNT_ACC_DAY] = 0;
842 0 $rh_file_lines->{$key} = join( $DELIM_FIELDS, @fields );
843 }
844 }
845  
846 0 ▶sub get_sorted_file_content {
Subroutine get_sorted_file_content: not called CC=1 SCAR=6.9
847 0 return( join( "\n", sort values %{$_[0]->{$KEY_FILE_LINES}} ) );
848 }
849  
850 0 ▶sub today_date_utc {
Subroutine today_date_utc: not called CC=1 SCAR=6.9
851 0 my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(time);
852 0 $year += 1900; # year counts from 1900 AD otherwise
853 0 $mon += 1; # ensure January is 1, not 0
854 0 my @parts = ($year, $mon, $mday, $hour, $min, $sec);
855 0 return( sprintf( "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d UTC", @parts ) );
856 }
857  
858 ######################################################################
859  
860 1 1;
861 __END__
« CGI/Portable/AdapterCGI.pm ↑ Summary CGI/Portable.pm »