Agent/Stamping.pm

filter: Statementstmt 78.2% 18 / 23 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 5 totaltotal 57.1% 24 / 42 CC 3 SCAR 7.7
CC
3
Cov
71%
stamping_fn
3.5
stamp_none
2.0
stamp_syslog
2.0
CRAP 2.2
« Agent/Driver.pm ↑ Summary Agent/Tag_List.pm »
1 ###########################################################################
2 #
3 # Stamping.pm
4 #
5 # Copyright (C) 1999 Raphael Manfredi.
6 # Copyright (C) 2002-2017 Mark Rogaski, mrogaski@cpan.org;
7 # all rights reserved.
8 #
9 # See the README file included with the
10 # distribution for license information.
11 #
12 ##########################################################################
13  
14 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 require Exporter;
16  
17 ########################################################################
18 package Log::Agent::Stamping;
19  
20 #
21 # Common time-stamping routines
22 #
23  
24 8 ▶use vars qw(@ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 8 @ISA = qw(Exporter);
26  
27 8 @EXPORT = qw(stamping_fn);
28  
29 8 my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
30 8 my @days = qw(Sun Mon Tue Wed Thu Fri Sat);
31  
32 #
33 # stamp_none
34 #
35 # No timestamp
36 #
37 0 ▶sub stamp_none {
Subroutine stamp_none: not called CC=1 SCAR=6.9
Pod undocumented
38 0 return '';
39 }
40  
41 #
42 # stamp_syslog
43 #
44 # Syslog-like stamping: "Oct 27 21:09:33"
45 #
46 0 ▶sub stamp_syslog {
Subroutine stamp_syslog: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
48 0 return sprintf "%s %2d %.2d:%.2d:%.2d",
49 $months[$mon], $mday, $hour, $min, $sec;
50 }
51  
52 #
53 # stamp_date
54 #
55 # Date format: "[Fri Oct 22 16:23:10 1999]"
56 #
57 0 ▶sub stamp_date {
Subroutine stamp_date: not called CC=1 SCAR=6.9
Pod undocumented
58 0 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
59 0 return sprintf "[%s %s %2d %.2d:%.2d:%.2d %d]",
60 $days[$wday], $months[$mon], $mday, $hour, $min, $sec, 1900 + $year;
61 }
62  
63 #
64 # stamp_own
65 #
66 # Own format: "99/10/24 09:43:49"
67 #
68 54 ▶sub stamp_own {
Subroutine stamp_own: called CC=1 SCAR=0.0
Pod undocumented
69 54 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
70 54 return sprintf "%.2d/%.2d/%.2d %.2d:%.2d:%.2d",
71 $year % 100, ++$mon, $mday, $hour, $min, $sec;
72 }
73  
74 8 my %stamping = (
75 'none' => \&stamp_none,
76 'syslog' => \&stamp_syslog,
77 'date' => \&stamp_date,
78 'own' => \&stamp_own,
79 );
80  
81 #
82 # stamping_fn
83 #
84 # Return proper time stamping function based on its 'tag'
85 # If tag is unknown, use stamp_own.
86 #
87 29 ▶sub stamping_fn {
Subroutine stamping_fn: called CC=3 SCAR=12.5
Pod undocumented
88 29 my ($tag) = @_;
89 29 ▶ return $stamping{$tag} if defined $tag && defined $stamping{$tag};
Branch: 1 branch
BranchTrueFalseTotal
if defined $tag and defined $stamping{$tag} 0 29 29
Condition33%1/3
defined $tag and defined $stamping{$tag}
!ll&&!rl&&r
2900
MC/DC0%0/2
defined $tag and defined $stamping{$tag}
defined $tag defined $stamping{$tag}
Truth table33%1/3
A and B
A= defined $tagB= defined $stamping{$tag}
ABresult
0X0
100
111
90 29 return \&stamp_own;
91 }
92  
93 8 1; # for require
94 __END__
« Agent/Driver.pm ↑ Summary Agent/Tag_List.pm »