Pad/Util.pm

filter: Statementstmt 100% 31 / 31 Branchbran 66.6% 8 / 12 Conditioncond 43.4% 10 / 23 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 73.9% 68 / 92 CC 16 SCAR 20.1
CC
16
Cov
74%
useColor
17.9
camelize
8.5
isValidName
3.0
CRAP 7.4
« Pad/Completion.pm ↑ Summary Pad/Help.pm »
1 package Getopt::Pad::Util;
2  
3 12 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 our $VERSION = '0.05';
11 12 our @EXPORT_OK = qw(camelize specError expandTilde useColor isValidName);
12  
13 4 ▶sub useColor($handle) {
Subroutine useColor: called CC=6 SCAR=28.9
Pod documented
14 4 ▶ return (-t $handle) && !length($ENV{NO_COLOR} // '') && (($ENV{TERM} // '') ne 'dumb') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
-t $handle && !length($ENV{'NO_COLOR'} // '') && ($ENV{'TERM'} // '') ne 'dumb' ? : 0 4 4
Condition20%2/10
-t $handle and not length($ENV{"NO_COLOR"} // "") and ($ENV{"TERM"} // "") ne "dumb"
!ll&&!rl&&r
400
-t $handle and not length($ENV{"NO_COLOR"} // "")
!ll&&!rl&&r
400
$ENV{"NO_COLOR"} // ""
l!l
00
$ENV{"TERM"} // ""
l!l
00
MC/DC0%0/3
-t $handle and not length($ENV{"NO_COLOR"} // "") and ($ENV{"TERM"} // "") ne "dumb"
-t $handle $ENV{"NO_COLOR"} $ENV{"TERM"}
Truth table25%1/4
A and not(B) and C
A= -t $handleB= $ENV{"NO_COLOR"}C= $ENV{"TERM"}
ABCresult
0XX0
11X0
1000
1011
15 }
16  
17 95 ▶sub expandTilde($path) {
Subroutine expandTilde: called CC=2 SCAR=7.2
Pod documented
18 95 ▶ return $path if !defined $ENV{HOME};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"HOME"} 0 95 95
19 95 return $path =~ s{^~(?=/|$)}{$ENV{HOME}}r;
20 }
21  
22 # The one shape an option name, an alias, an arg short name and a command
23 # name share: a letter, then word characters or dashes.
24 1303 ▶sub isValidName($name) {
Subroutine isValidName: called CC=3 SCAR=11.0
Pod documented
25 1303 ▶ return defined $name && $name =~ /\A[a-zA-Z][\w-]*\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $name && $name =~ /\A[a-zA-Z][\w-]*\z/u ? : 1301 2 1303
Condition100%3/3
defined $name and $name =~ /\A[a-zA-Z][\w-]*\z/u
!ll&&!rl&&r
111301
MC/DC100%2/2
defined $name and $name =~ /\A[a-zA-Z][\w-]*\z/u
defined $name $name =~ /\A[a-zA-Z][\w-]*\z/u
Truth table100%3/3
A and B
A= defined $nameB= $name =~ /\A[a-zA-Z][\w-]*\z/u
ABresult
0X0
100
111
26 }
27  
28 1171 ▶sub camelize($name) {
Subroutine camelize: called CC=6 SCAR=21.4
Pod documented
29 1171 ▶ my ($first, @rest) = split /[-_]+/, $name // '';
Condition50%1/2
$name // ""
l!l
11710
MC/DC0%0/1
$name // ""
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
30 1171 ▶ specError("cannot derive a reader name from '%s'", $name // '') if !defined $first || $first eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $first or $first eq "" 0 1171 1171
Condition20%1/5
not defined $first or $first eq ""
l!l&&r!l&&!r
001171
$name // ""
l!l
00
MC/DC0%0/2
not defined $first or $first eq ""
not defined $first $first eq ""
MC/DC0%0/1
$name // ""
$name
Truth table33%1/3
not(A) or B
A= not defined $firstB= $first eq ""
ABresult
1X1
011
000
Truth table0%0/2
A
A= $name
Aresult
11
00
31  
32 1171 my $reader = $first . join('', map { ucfirst } @rest);
33 1171 ▶ specError("derived reader name '%s' (from '%s') is not a valid identifier", $reader, $name) if $reader !~ /^[a-zA-Z_]\w*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $reader =~ /^[a-zA-Z_]\w*$/u 0 1171 1171
34  
35 1171 return $reader;
36 }
37  
38 # Spec mistakes are programmer errors: report them at the first caller
39 # outside Getopt::Pad, normally the GetOptions call, not at the library
40 # frame that noticed them.
41 54 ▶sub specError($format, @args) {
Subroutine specError: called CC=3 SCAR=11.0
Pod documented
42 54 my $frame = 0;
43 54 ▶ $frame++ while (caller($frame + 1))[0] && (caller($frame))[0] =~ /\AGetopt::Pad(?:::|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
(caller $frame + 1)[0] and (caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u and do { ++$frame } 202 54 256
Condition100%3/3
(caller $frame + 1)[0] and (caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u
!ll&&!rl&&r
153202
MC/DC100%2/2
(caller $frame + 1)[0] and (caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u
(caller $frame + 1)[0] (caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u
Truth table100%3/3
A and B
A= (caller $frame + 1)[0]B= (caller $frame)[0] =~ /\AGetopt::Pad(?:::|\z)/u
ABresult
0X0
100
111
44 54 my (undef, $file, $line) = caller($frame);
45 54 die sprintf("Getopt::Pad spec: %s at %s line %d.\n", sprintf($format, @args), $file, $line);
46 }
47  
48 12 1;
49  
50 __END__
« Pad/Completion.pm ↑ Summary Pad/Help.pm »