RefVars/Builtins.pm

filter: Statementstmt 96.5% 84 / 87 Branchbran 71.8% 46 / 64 Conditioncond 68.0% 17 / 25 MC/DCmcdc 46.6% 7 / 15 Subroutinesub 95.8% 23 / 24 Podpod 100% 1 / 1 totaltotal 82.4% 178 / 216 CC 46 SCAR 16.8
CC
46
Cov
84%
_m
11.4
_s
9.0
_tr
6.0
CRAP 5.4
« RefVars.pm ↑ Summary
1 # lib/Config/INI/RefVars/Builtins.pm
2 package Config::INI::RefVars::Builtins;
3  
4 31 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 31 ▶use File::Spec::Functions;# qw(catdir catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use File::Basename qw(dirname basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 31 our $VERSION = '1.07';
13  
14  
15 192 ▶sub default_dispatch_table {
Subroutine default_dispatch_table: called CC=1 SCAR=0.0
Pod documented
16 return {
17 192 catdir => \&File::Spec::Functions::catdir,
18 catfile => \&File::Spec::Functions::catfile,
19 catpath => \&_catpath,
20 ignore => \&_ignore,
21 concat => \&_concat,
22 join => \&_join,
23 substr => \&_substr,
24 x => \&_x,
25 'and' => \&_and,
26 'or' => \&_or,
27 'if' => \&_if,
28 s => \&_s,
29 tr => \&_tr,
30 m => \&_m,
31 not => \&_not,
32 eq => \&_eq,
33 dirname => \&dirname,
34 basename => \&basename,
35 };
36 }
37  
38 0 ▶sub _catpath {
Subroutine _catpath: not called CC=2 SCAR=17.9
39 0 ▶ die("catpath: expected 3 arguments\n") unless @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
40 0 return File::Spec::Functions::catpath(@_);
41 }
42  
43  
44 2 ▶sub _clean_error {
Subroutine _clean_error: called CC=1 SCAR=0.0
45 2 my ($error) = @_;
46 2 chomp($error);
47 2 $error =~ s/\s+at\s+\S+\s+line\s+\d+\.?\z//;
48 2 return $error;
49 }
50  
51  
52 12 ▶sub _ignore {
Subroutine _ignore: called CC=1 SCAR=0.0
53 12 return "";
54 }
55  
56  
57 9 ▶sub _concat {
Subroutine _concat: called CC=1 SCAR=0.0
58 9 return join("", @_);
59 }
60  
61  
62 14 ▶sub _join {
Subroutine _join: called CC=2 SCAR=7.6
63 14 ▶ return @_ ? join(shift(@_), @_) : "";
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 14 0 14
64 }
65  
66  
67 8 ▶sub _substr {
Subroutine _substr: called CC=5 SCAR=16.1
68 8 ▶ die("substr: expected 2 or 3 arguments\n") if @_ < 2 || @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 3 5 8
Condition100%3/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
215
MC/DC100%2/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table100%3/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
69  
70 5 my $warning = "";
71  
72 2 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 2 $warning = _clean_error($_[0]);
74 5 };
75  
76 5 ▶ my $result = @_ == 2
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 2 3 5
77 ? substr($_[0], $_[1]) : substr($_[0], $_[1], $_[2]);
78  
79 5 ▶ die("substr: $warning\n") if $warning ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $warning ne "" 2 3 5
80 3 return $result;
81 }
82  
83  
84 3 ▶sub _x {
Subroutine _x: called CC=3 SCAR=11.4
85 3 ▶ die("x: expected 2 arguments\n") if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 3 3
86  
87 3 my ($str, $n) = @_;
88  
89 3 ▶ die("x: second argument must be a non-negative integer\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /^\+?[0-9]+$/ 0 3 3
90 unless $n =~ /^\+?[0-9]+$/;
91  
92 3 return $str x $n;
93 }
94  
95  
96 5 ▶sub _and {
Subroutine _and: called CC=4 SCAR=13.9
97 5 foreach my $arg (@_) {
98 8 ▶ return "" if $arg eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "" 2 6 8
99 }
100 3 ▶ return @_ ? $_[-1] : "";
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 1 3
101 }
102  
103  
104 5 ▶sub _or {
Subroutine _or: called CC=3 SCAR=11.0
105 5 foreach my $arg (@_) {
106 8 ▶ return $arg if $arg ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $arg ne "" 3 5 8
107 }
108 2 return "";
109 }
110  
111  
112 6 ▶sub _if {
Subroutine _if: called CC=5 SCAR=17.1
113 6 ▶ die("if: expected 2 or 3 arguments\n") if @_ < 2 || @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 6 6
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
006
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
114 6 ▶ return $_[0] ne "" ? $_[1] : ($_[2] // "");
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ne '' ? : 3 3 6
Condition100%2/2
$_[2] // ""
l!l
21
MC/DC100%1/1
$_[2] // ""
$_[2]
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
115 }
116  
117  
118 10 ▶sub _s {
Subroutine _s: called CC=9 SCAR=22.0
119 10 ▶ die("s: expected 3 or 4 arguments\n") if @_ < 3 || @_ > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 or @_ > 4 1 9 10
Condition66%2/3
@_ < 3 or @_ > 4
l!l&&r!l&&!r
109
MC/DC50%1/2
@_ < 3 or @_ > 4
@_ < 3 @_ > 4
Truth table66%2/3
A or B
A= @_ < 3B= @_ > 4
ABresult
1X1
011
000
120  
121 9 my ($str, $pattern, $replacement, $mods) = @_;
122 9 ▶ $mods //= "";
Condition100%2/2
$mods //= ""
l!l
54
MC/DC100%1/1
$mods //= ""
$mods
Truth table100%2/2
A
A= $mods
Aresult
11
00
123  
124 9 ▶ die("s: unsupported modifier '$mods'\n") if $mods !~ /^[gimsx]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mods =~ /^[gimsx]*$/ 2 7 9
125  
126 7 ▶ die("s: regex code blocks are not allowed\n") if $pattern =~ /\(\?\??\{/;
Branch: 1 branch
BranchTrueFalseTotal
if $pattern =~ /\(\?\??\{/ 2 5 7
127  
128 5 my $global = $mods =~ s/g//g;
129 5 ▶ my $re = eval { $mods eq "" ? qr/$pattern/ : qr/(?$mods:$pattern)/; };
Branch: 1 branch
BranchTrueFalseTotal
$mods eq '' ? : 4 1 5
130 5 ▶ die("s: ", _clean_error($@), "\n") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
131  
132 5 ▶ if ($global) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global) { } 2 3 5
133 2 $str =~ s/$re/$replacement/g;
134 }
135 else {
136 3 $str =~ s/$re/$replacement/;
137 }
138 5 return $str;
139 }
140  
141  
142 5 ▶sub _pick_tr_delim {
Subroutine _pick_tr_delim: called CC=4 SCAR=14.5
143 5 my @values = @_;
144  
145 31 ▶ no warnings 'qw';
Subroutine BEGIN: called CC=1 SCAR=0.0
146 5 foreach my $delim (qw(| ! / : ; # ~ @ % ^ * + = ?)) {
147 5 ▶ return $delim if !grep { index($_ // "", $delim) >= 0 } @values;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($_ // "", $delim) != -1;} @values 5 0 5
Condition50%1/2
$_ // ""
l!l
100
MC/DC0%0/1
$_ // ""
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
148 }
149 0 die("tr: no safe delimiter found\n");
150 }
151  
152  
153 8 ▶sub _tr {
Subroutine _tr: called CC=6 SCAR=18.0
154 8 ▶ die("tr: expected 3 or 4 arguments\n") if @_ < 3 || @_ > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 or @_ > 4 1 7 8
Condition66%2/3
@_ < 3 or @_ > 4
l!l&&r!l&&!r
107
MC/DC50%1/2
@_ < 3 or @_ > 4
@_ < 3 @_ > 4
Truth table66%2/3
A or B
A= @_ < 3B= @_ > 4
ABresult
1X1
011
000
155  
156 7 my ($str, $search, $replacement, $mods) = @_;
157 7 ▶ $mods //= "";
Condition100%2/2
$mods //= ""
l!l
52
MC/DC100%1/1
$mods //= ""
$mods
Truth table100%2/2
A
A= $mods
Aresult
11
00
158  
159 7 ▶ die("tr: unsupported modifier '$mods'\n") if $mods !~ /^[cds]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mods =~ /^[cds]*$/ 2 5 7
160  
161 5 my $delim = _pick_tr_delim($search, $replacement);
162 5 my $code = "\$str =~ tr${delim}${search}${delim}${replacement}${delim}${mods};";
163 5 ▶ eval "$code; 1" or die("tr: ", _clean_error($@), "\n");
Branch: 1 branch
BranchTrueFalseTotal
eval "$code; 1" or die "tr: ", _clean_error($@), "\n" 5 0 5
164  
165 5 return $str;
166 }
167  
168  
169 6 ▶sub _m {
Subroutine _m: called CC=9 SCAR=24.3
170 6 ▶ die("m: expected 2 or 3 arguments\n") if @_ < 2 || @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 6 6
Condition33%1/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
006
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
171  
172 6 my ($str, $pattern, $mods) = @_;
173 6 ▶ $mods //= "";
Condition50%1/2
$mods //= ""
l!l
06
MC/DC0%0/1
$mods //= ""
$mods
Truth table50%1/2
A
A= $mods
Aresult
11
00
174  
175 6 ▶ die("m: unsupported modifier '$mods'\n") if $mods !~ /^[imsx]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mods =~ /^[imsx]*$/ 0 6 6
176 6 ▶ die("m: regex code blocks are not allowed\n") if $pattern =~ /\(\?\??\{/;
Branch: 1 branch
BranchTrueFalseTotal
if $pattern =~ /\(\?\??\{/ 0 6 6
177  
178 6 ▶ my $re = eval { $mods eq "" ? qr/$pattern/ : qr/(?$mods:$pattern)/; };
Branch: 1 branch
BranchTrueFalseTotal
$mods eq '' ? : 6 0 6
179 6 ▶ die("m: ", _clean_error($@), "\n") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
180  
181 6 ▶ return $str =~ $re ? "1" : "";
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /$re/ ? : 4 2 6
182 }
183  
184  
185 1 ▶sub _not {
Subroutine _not: called CC=3 SCAR=12.0
186 1 ▶ die("not: expected 1 argument\n") if @_ != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 1 0 1 1
187 1 ▶ return $_[0] eq "" ? "1" : "";
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq '' ? : 1 0 1
188 }
189  
190  
191 1 ▶sub _eq {
Subroutine _eq: called CC=3 SCAR=12.0
192 1 ▶ die("eq: expected 2 arguments\n") if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 1 1
193 1 ▶ return $_[0] eq $_[1] ? "1" : "";
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq $_[1] ? : 1 0 1
194 }
195  
196 31 1;
197  
198  
199 __END__
« RefVars.pm ↑ Summary