Fu/Chomp.pm

filter: Statementstmt 86.2% 69 / 80 Branchbran 59.3% 19 / 32 Conditioncond 66.6% 8 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 3 totaltotal 73.7% 104 / 141 CC 22 SCAR 31.2
CC
22
Cov
77%
fu_chomp
29.4
DelHandler
6.0
BEGIN
1.0
CRAP 22.7
↑ Summary Fu/Color.pm »
1 package Log::Fu::Chomp;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 our @EXPORT = qw(fu_chomp);
7  
8 5 ▶use Log::Fu::Common qw(%Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 my $HKEY_MORE_CHAR = 'StripMoreIndicator';
11 5 my $HKEY_STRIP = 'Strip';
12 5 my $HKEY_MAX_COMPONENTS = 'StripMaxComponents';
13 5 my $HKEY_STRIP_WIDTH = 'StripCallerWidth';
14 5 my $HKEY_STRIP_KEEP = 'StripKeepChars';
15 5 my $HKEY_STRIP_TLNS = 'StripTopLevelNamespace';
16 5 my $HKEY_STRIP_SUB = 'StripSubBasename';
17  
18  
19 #Filler 'more' char
20 5 $Config{$HKEY_MORE_CHAR} = '~';
21  
22 #Boolean, whether to strip
23 5 $Config{$HKEY_STRIP} = 0;
24  
25 #How many intermediate components to keep (max)
26 5 $Config{$HKEY_MAX_COMPONENTS} = 2;
27  
28 #How small can caller info be to ignore stripping
29 5 $Config{$HKEY_STRIP_WIDTH} = 10;
30  
31 #How many characters to keep for each shortened component
32 5 $Config{$HKEY_STRIP_KEEP} = 2;
33  
34 #Whether to strip the top-level namespace
35 5 $Config{$HKEY_STRIP_TLNS} = 0;
36  
37 #Maximum length for function basname
38 5 $Config{$HKEY_STRIP_SUB} = 8;
39  
40 5 my %Handlers = ();
41 5 my %HandlerCache = ();
42  
43 1 ▶sub AddHandler {
Subroutine AddHandler: called CC=1 SCAR=0.0
Pod undocumented
44 1 my ($match,$code) = @_;
45 1 $Handlers{$match} = $code;
46 1 %HandlerCache = ();
47 }
48  
49 0 ▶sub DelHandler {
Subroutine DelHandler: not called CC=2 SCAR=17.9
Pod undocumented
50 0 my ($match) = @_;
51 0 ▶ if(delete $Handlers{$match}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $Handlers{$match}) 0 0 0
52 0 %HandlerCache = ();
53 }
54 }
55  
56 19 ▶sub fu_chomp {
Subroutine fu_chomp: called CC=21 SCAR=33.8
Pod undocumented
57 19 my $sub = $_[0];
58
59 GT_FETCH_CACHE:
60 20 ▶ if(%Handlers) {
Branch: 1 branch
BranchTrueFalseTotal
if (%Handlers) 2 18 20
61 2 my $code = $HandlerCache{$sub};
62 2 ▶ if(defined $code && ref $code ne 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $code and ref $code ne 'CODE') { } 0 2 2
elsif (defined $code) { } 1 1 2
Condition66%2/3
defined $code and ref $code ne "CODE"
!ll&&!rl&&r
110
MC/DC0%0/2
defined $code and ref $code ne "CODE"
defined $code ref $code ne "CODE"
Truth table66%2/3
A and B
A= defined $codeB= ref $code ne "CODE"
ABresult
0X0
100
111
63 0 goto GT_WE_PROCESS;
64 } elsif (defined $code) {
65 1 goto &$code;
66 } else {
67 1 my $module = $sub;
68 1 $module =~ s/::[^:]+$//g;
69 0 foreach my $key (reverse sort { length($a) <=> length($b) }
70 keys %Handlers) {
71 1 ▶ if(index($module, $key) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($module, $key) != -1) 1 0 1
72 1 $HandlerCache{$sub} = $Handlers{$key};
73 1 goto GT_FETCH_CACHE;
74 }
75 }
76 0 $HandlerCache{$sub} = 0;
77 }
78 }
79
80 GT_WE_PROCESS:
81 18 ▶ return $sub unless $Config{$HKEY_STRIP};
Branch: 1 branch
BranchTrueFalseTotal
unless $Log::Fu::Chomp::Config{$HKEY_STRIP} 16 2 18
82 2 ▶ return $sub if $Log::Fu::NO_STRIP;
Branch: 1 branch
BranchTrueFalseTotal
if $Log::Fu::NO_STRIP 0 2 2
83
84 2 my $maxwidth;
85
86 2 ▶ if( ($maxwidth = $Config{$HKEY_STRIP_WIDTH}) ){
Branch: 1 branch
BranchTrueFalseTotal
if ($maxwidth = $Log::Fu::Chomp::Config{$HKEY_STRIP_WIDTH}) 2 0 2
87 2 ▶ return $sub if length($sub) < $maxwidth;
Branch: 1 branch
BranchTrueFalseTotal
if length $sub < $maxwidth 0 2 2
88 }
89
90 2 my @orig_components = split(/::/, $sub);
91 2 my @components;
92 2 my $sub_basename = pop @orig_components;
93
94 2 my $tlns = shift @orig_components;
95 2 ▶ $tlns .= "::" if $tlns;
Branch: 1 branch
BranchTrueFalseTotal
if $tlns 2 0 2
96
97 #Strip top-level component
98 2 my $tlns_len = $Config{$HKEY_STRIP_TLNS} + length($Config{$HKEY_MORE_CHAR});
99 2 ▶ if($Config{$HKEY_STRIP_TLNS} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($Log::Fu::Chomp::Config{$HKEY_STRIP_TLNS} and $tlns_len - 1 and length $tlns > $tlns_len) 1 1 2
Condition66%4/6
$Log::Fu::Chomp::Config{$HKEY_STRIP_TLNS} and $tlns_len - 1 and length $tlns > $tlns_len
!ll&&!rl&&r
101
$Log::Fu::Chomp::Config{$HKEY_STRIP_TLNS} and $tlns_len - 1
!ll&&!rl&&r
101
MC/DC33%1/3
$Log::Fu::Chomp::Config{$HKEY_STRIP_TLNS} and $tlns_len - 1 and length $tlns > $tlns_len
$Log::Fu::Chomp::Config{$HKEY_STRIP_TLNS} $tlns_len - 1 length $tlns > $tlns_len
Truth table50%2/4
A and B and C
A= $Log::Fu::Chomp::Config{$HKEY_STRIP_TLNS}B= $tlns_len - 1C= length $tlns > $tlns_len
ABCresult
0XX0
10X0
1100
1111
100 $tlns_len-1 && length($tlns) > $tlns_len) {
101 1 $tlns = substr($tlns, 0, $Config{$HKEY_STRIP_TLNS});
102 1 $tlns .= $Config{$HKEY_MORE_CHAR};
103 }
104 2 push @components, $tlns;
105
106 2 ▶ if($Config{$HKEY_MAX_COMPONENTS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Log::Fu::Chomp::Config{$HKEY_MAX_COMPONENTS}) 2 0 2
107 2 ▶ while(scalar @orig_components > $Config{$HKEY_MAX_COMPONENTS}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @orig_components > $Log::Fu::Chomp::Config{$HKEY_MAX_COMPONENTS}) 0 2 2
108 0 shift @orig_components;
109 }
110 }
111
112 #Strip intermediary components
113 2 my $new_len_min = $Config{$HKEY_STRIP_KEEP} + length($Config{$HKEY_MORE_CHAR});
114 2 ▶ while ( (my $comp = shift @orig_components) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = shift @orig_components) 0 2 2
115 0 ▶ if(length($comp) <= $new_len_min) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $comp <= $new_len_min) { } 0 0 0
116 } else {
117 0 $comp = substr($comp, 0, $Config{$HKEY_STRIP_KEEP});
118 0 $comp .= $Config{$HKEY_MORE_CHAR};
119 }
120 0 push @components, $comp;
121 }
122
123 #Strip the basename of the sub
124 2 my $sub_len_min = $Config{$HKEY_STRIP_SUB} + length($Config{$HKEY_MORE_CHAR});
125 2 ▶ if($Config{$HKEY_STRIP_SUB} && length($sub_basename) > $sub_len_min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Log::Fu::Chomp::Config{$HKEY_STRIP_SUB} and length $sub_basename > $sub_len_min) 1 1 2
Condition66%2/3
$Log::Fu::Chomp::Config{$HKEY_STRIP_SUB} and length $sub_basename > $sub_len_min
!ll&&!rl&&r
101
MC/DC50%1/2
$Log::Fu::Chomp::Config{$HKEY_STRIP_SUB} and length $sub_basename > $sub_len_min
$Log::Fu::Chomp::Config{$HKEY_STRIP_SUB} length $sub_basename > $sub_len_min
Truth table66%2/3
A and B
A= $Log::Fu::Chomp::Config{$HKEY_STRIP_SUB}B= length $sub_basename > $sub_len_min
ABresult
0X0
100
111
126 1 my $offset = length($sub_basename) - $Config{$HKEY_STRIP_SUB};
127 1 $sub_basename = $Config{$HKEY_MORE_CHAR} . substr($sub_basename, $offset);
128 #Make sure we have an offset. We wi
129 }
130
131 2 push @components, $sub_basename;
132 2 return join("", @components);
133 }
134  
135  
136 5 1;
↑ Summary Fu/Color.pm »