Layout/Utils.pm

filter: Statementstmt 75.0% 33 / 44 Branchbran 8.3% 1 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 61.5% 8 / 13 Podpod 0.0% 0 / 6 totaltotal 49.4% 42 / 85 CC 10 SCAR 22.2
CC
10
Cov
55%
maybe
30.0
min
6.0
max
6.0
CRAP 9.2
« Layout/Markdown.pm ↑ Summary Layout/Testing.pm »
1 #! perl
2  
3 package Text::Layout::Utils;
4  
5 8 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use feature qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶no warnings "experimental::signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 our @EXPORT;
13  
14 # Split (pseudo) command line into key/value pairs.
15  
16 2 ▶sub parse_kv ( @lines ) {
Subroutine parse_kv: called CC=4 SCAR=15.2
Pod undocumented
17  
18 8 ▶ use Text::ParseWords qw(shellwords);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 my @words = shellwords(@lines);
20  
21 2 my $res = {};
22 2 foreach ( @words ) {
23 3 ▶ if ( /^(.*?)=(.+)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^(.*?)=(.+)/u) { } 3 0 3
elsif (/^no[-_]?(.+)/u) { } 0 0 0
24 3 $res->{$1} = $2;
25 }
26 elsif ( /^no[-_]?(.+)/ ) {
27 0 $res->{$1} = 0;
28 }
29 else {
30 0 $res->{$_}++;
31 }
32 }
33  
34 2 return $res;
35 }
36  
37 8 push( @EXPORT, 'parse_kv' );
38  
39 # Remove markup.
40 0 ▶sub demarkup ( $t ) {
Subroutine demarkup: not called CC=1 SCAR=6.9
Pod undocumented
41 0 return join( '', grep { ! /^\</ } splitmarkup($t) );
42 }
43 8 push( @EXPORT, 'demarkup' );
44  
45 # Split into markup/nonmarkup segments.
46 0 ▶sub splitmarkup ( $t ) {
Subroutine splitmarkup: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my @t = split( qr;(</?(?:[-\w]+|span\s.*?)>);, $t );
48 0 return @t;
49 }
50 8 push( @EXPORT, 'splitmarkup' );
51  
52 # For conditional filling of hashes.
53 0 ▶sub maybe ( $key, $value, @rest ) {
Subroutine maybe: not called CC=5 SCAR=34.0
Pod undocumented
54 0 ▶ if (defined $key and defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key and defined $value) { } 0 0 0
Condition0%0/3
defined $key and defined $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and defined $value
defined $key defined $value
Truth table0%0/3
A and B
A= defined $keyB= defined $value
ABresult
0X0
100
111
55 0 return ( $key, $value, @rest );
56 }
57 else {
58 0 ▶ ( defined($key) || @rest ) ? @rest : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $key || @rest ? : 0 0 0
Condition0%0/3
defined $key or @rest
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $key or @rest
defined $key @rest
Truth table0%0/3
A or B
A= defined $keyB= @rest
ABresult
1X1
011
000
59 }
60 }
61 8 push( @EXPORT, "maybe" );
62  
63 # Min/Max.
64 0 ▶sub min { $_[0] < $_[1] ? $_[0] : $_[1] }
Subroutine min: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] < $_[1] ? : 0 0 0
65 0 ▶sub max { $_[0] > $_[1] ? $_[0] : $_[1] }
Subroutine max: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > $_[1] ? : 0 0 0
66  
67 8 push( @EXPORT, "min", "max" );
68  
69 8 1;
« Layout/Markdown.pm ↑ Summary Layout/Testing.pm »