blib/lib/String/Indent.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 6 / 6 Conditioncond 77.2% 17 / 22 MC/DCmcdc 46.1% 6 / 13 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 84.8% 67 / 79 CC 12 SCAR 22.4
CC
12
Cov
92%
indent
12.2
BEGIN
1.0
BEGIN
1.0
CRAP 9.4
↑ Summary
1 package String::Indent;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 2 our $DATE = '2024-01-25'; # DATE
9 2 our $DIST = 'String-Indent'; # DIST
10 2 our $VERSION = '0.040'; # VERSION
11  
12 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 our @EXPORT_OK = qw(
14 indent
15 );
16  
17 6 ▶sub indent {
Subroutine indent: called CC=12 SCAR=25.0
Pod documented
18 6 my ($indent, $str, $opts) = @_;
19 6 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
51
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
20  
21 6 ▶ my $ibl = $opts->{indent_blank_lines} // 1;
Condition100%2/2
$opts->{"indent_blank_lines"} // 1
l!l
15
MC/DC100%1/1
$opts->{"indent_blank_lines"} // 1
$opts->{"indent_blank_lines"}
Truth table100%2/2
A
A= $opts->{"indent_blank_lines"}
Aresult
11
00
22 6 ▶ my $fli = $opts->{first_line_indent} // $indent;
Condition66%2/3
$opts->{"first_line_indent"} // $indent
l!l&&r!l&&!r
240
MC/DC0%0/2
$opts->{"first_line_indent"} // $indent
$opts->{"first_line_indent"} $indent
Truth table66%2/3
A // B
A= $opts->{"first_line_indent"}B= $indent
ABresult
1X1
011
000
23 6 ▶ my $sli = $opts->{subsequent_lines_indent} // $indent;
Condition66%2/3
$opts->{"subsequent_lines_indent"} // $indent
l!l&&r!l&&!r
240
MC/DC0%0/2
$opts->{"subsequent_lines_indent"} // $indent
$opts->{"subsequent_lines_indent"} $indent
Truth table66%2/3
A // B
A= $opts->{"subsequent_lines_indent"}B= $indent
ABresult
1X1
011
000
24 6 ▶ my $flopi = $opts->{first_line_of_para_indent} // $sli // $indent;
Condition50%3/6
($opts->{"first_line_of_para_indent"} // $sli) // $indent
l!l&&r!l&&!r
600
$opts->{"first_line_of_para_indent"} // $sli
l!l&&r!l&&!r
150
MC/DC0%0/3
($opts->{"first_line_of_para_indent"} // $sli) // $indent
$opts->{"first_line_of_para_indent"} $sli $indent
Truth table50%2/4
A // B // C
A= $opts->{"first_line_of_para_indent"}B= $sliC= $indent
ABCresult
1XX1
01X1
0011
0000
25 #say "D:ibl=<$ibl>, fli=<$fli>, flopi=<$flopi>, sli=<$sli>";
26  
27 6 my $i = 0;
28 6 my $prev_blank;
29 6 ▶ $str =~ s/^([^\r\n]?)/$i++; my $blank = !$1; my $start_para = $i==1 || $prev_blank; $prev_blank = $blank; !$ibl && $blank ? "$1" : $i==1 ? "$fli$1" : $start_para ? "$flopi$1" : "$sli$1"/egm;
Branch: 3 branches
BranchTrueFalseTotal
!$ibl && $blank ? : 1 18 19
$i == 1 ? : 6 12 18
$start_para ? : 5 7 12
Condition100%6/6
$i == 1 || $prev_blank
l!l&&r!l&&!r
658
not $ibl and $blank
!ll&&!rl&&r
1621
MC/DC100%2/2
$i == 1 || $prev_blank
$i == 1 $prev_blank
MC/DC100%2/2
not $ibl and $blank
not $ibl $blank
Truth table100%3/3
A || B
A= $i == 1B= $prev_blank
ABresult
1X1
011
000
Truth table100%3/3
not(A) and B
A= not $iblB= $blank
ABresult
0X0
100
111
30 6 $str;
31 }
32  
33 2 1;
34 # ABSTRACT: String indenting routines
35  
36 __END__
↑ Summary