To/Doc/Role/Section/AddTextLines.pm

filter: Statementstmt 24.3% 18 / 74 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 40 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 13.7% 23 / 167 CC 30 SCAR 67.1
CC
30
Cov
13%
add_doc_lines
930.0
BEGIN
1.0
BEGIN
1.0
CRAP 820.7
« Sub/To/POD.pm ↑ Summary Sub/To/Text.pm »
1 package Perinci::To::Doc::Role::Section::AddTextLines;
2  
3 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 requires 'doc_lines';
8 4 requires 'doc_indent_level';
9 4 requires 'doc_indent_str';
10 1 ▶has doc_wrap => (is => 'rw', default => sub {1});
Subroutine __ANON__: called CC=1 SCAR=0.0
11  
12 4 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 4 our $DATE = '2023-07-09'; # DATE
14 4 our $DIST = 'Perinci-To-Doc'; # DIST
15 4 our $VERSION = '0.881'; # VERSION
16  
17 0 ▶sub add_doc_lines {
Subroutine add_doc_lines: not called CC=30 SCAR=68.4
Pod documented
18 0 my $self = shift;
19 0 my $opts;
20 0 ▶ if (ref($_[0]) eq 'HASH') { $opts = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "HASH") 0 0 0
21 0 ▶ $opts //= {};
Condition0%0/2
$opts //= {}
l!l
00
MC/DC0%0/1
$opts //= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
22  
23 0 ▶ my @lines = map { $_ . (/\n\z/s ? "" : "\n") }
Branch: 1 branch
BranchTrueFalseTotal
/\n\z/s ? : 0 0 0
24 0 ▶ map {/\n/ ? split /\n/ : $_} @_;
Branch: 1 branch
BranchTrueFalseTotal
/\n/ ? : 0 0 0
25  
26 # debug
27 #my @c = caller(2);
28 #$c[1] =~ s!.+/!!;
29 #@lines = map {"[from $c[1]:$c[2]]$_"} @ lines;
30  
31 0 my $indent = $self->doc_indent_str x $self->doc_indent_level;
32 0 ▶ my $wrap = $opts->{wrap} // $self->doc_wrap;
Condition0%0/3
$opts->{"wrap"} // $self->doc_wrap
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"wrap"} // $self->doc_wrap
$opts->{"wrap"} $self->doc_wrap
Truth table0%0/3
A // B
A= $opts->{"wrap"}B= $self->doc_wrap
ABresult
1X1
011
000
33  
34 0 ▶ if ($wrap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrap) { } 0 0 0
35 0 require Text::Wrap;
36  
37 # split into paragraphs, merge each paragraph text into a single line
38 # first
39 0 my @para;
40 0 my $i = 0;
41 0 my ($start, $type);
42 0 $type = '';
43 #$log->warnf("lines=%s", \@lines);
44 0 for (@lines) {
45 0 ▶ if (/^\s*$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^\s*$/) { } 0 0 0
elsif (/^\s{4,}\S+/ and !$i || $type eq 'verbatim' || @para && $para[-1][0] eq 'blank') { } 0 0 0
46 0 ▶ if (defined($start) && $type ne 'blank') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start and $type ne "blank") 0 0 0
Condition0%0/3
defined $start and $type ne "blank"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start and $type ne "blank"
defined $start $type ne "blank"
Truth table0%0/3
A and B
A= defined $startB= $type ne "blank"
ABresult
0X0
100
111
47 0 push @para, [$type, [@lines[$start..$i-1]]];
48 0 undef $start;
49 }
50 0 ▶ $start //= $i;
Condition0%0/3
$start //= $i
l!l&&r!l&&!r
000
MC/DC0%0/2
$start //= $i
$start $i
Truth table0%0/3
A //= B
A= $startB= $i
ABresult
1X1
011
000
51 0 $type = 'blank';
52 ▶ } elsif (/^\s{4,}\S+/ && (!$i || $type eq 'verbatim' ||
Condition0%0/12
/^\s{4,}\S+/ and !$i || $type eq "verbatim" || @para && $para[-1][0] eq "blank"
!ll&&!rl&&r
000
not $i or $type eq "verbatim" or @para and $para[-1][0] eq "blank"
l!l&&r!l&&!r
000
not $i or $type eq "verbatim"
l!l&&r!l&&!r
000
@para and $para[-1][0] eq "blank"
!ll&&!rl&&r
000
MC/DC0%0/5
/^\s{4,}\S+/ and !$i || $type eq "verbatim" || @para && $para[-1][0] eq "blank"
/^\s{4,}\S+/ not $i $type eq "verbatim" @para $para[-1][0] eq "blank"
Truth table0%0/6
A and not(B) or C or D and E
A= /^\s{4,}\S+/B= not $iC= $type eq "verbatim"D= @paraE= $para[-1][0] eq "blank"
ABCDEresult
0XXXX0
1000X0
100100
11XXX1
101XX1
100111
53 (@para && $para[-1][0] eq 'blank'))) {
54 0 ▶ if (defined($start) && $type ne 'verbatim') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start and $type ne "verbatim") 0 0 0
Condition0%0/3
defined $start and $type ne "verbatim"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start and $type ne "verbatim"
defined $start $type ne "verbatim"
Truth table0%0/3
A and B
A= defined $startB= $type ne "verbatim"
ABresult
0X0
100
111
55 0 push @para, [$type, [@lines[$start..$i-1]]];
56 0 undef $start;
57 }
58 0 ▶ $start //= $i;
Condition0%0/3
$start //= $i
l!l&&r!l&&!r
000
MC/DC0%0/2
$start //= $i
$start $i
Truth table0%0/3
A //= B
A= $startB= $i
ABresult
1X1
011
000
59 0 $type = 'verbatim';
60 } else {
61 0 ▶ if (defined($start) && $type ne 'normal') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start and $type ne "normal") 0 0 0
Condition0%0/3
defined $start and $type ne "normal"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start and $type ne "normal"
defined $start $type ne "normal"
Truth table0%0/3
A and B
A= defined $startB= $type ne "normal"
ABresult
0X0
100
111
62 0 push @para, [$type, [@lines[$start..$i-1]]];
63 0 undef $start;
64 }
65 0 ▶ $start //= $i;
Condition0%0/3
$start //= $i
l!l&&r!l&&!r
000
MC/DC0%0/2
$start //= $i
$start $i
Truth table0%0/3
A //= B
A= $startB= $i
ABresult
1X1
011
000
66 0 $type = 'normal';
67 }
68 #$log->warnf("i=%d, lines=%s, start=%s, type=%s",
69 # $i, $_, $start, $type);
70 0 $i++;
71 }
72 0 ▶ if (@para && $para[-1][0] eq $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (@para and $para[-1][0] eq $type) { } 0 0 0
Condition0%0/3
@para and $para[-1][0] eq $type
!ll&&!rl&&r
000
MC/DC0%0/2
@para and $para[-1][0] eq $type
@para $para[-1][0] eq $type
Truth table0%0/3
A and B
A= @paraB= $para[-1][0] eq $type
ABresult
0X0
100
111
73 0 push @{ $para[-1][1] }, [$type, [@lines[$start..$i-1]]];
74 } else {
75 0 push @para, [$type, [@lines[$start..$i-1]]];
76 }
77 #$log->warnf("para=%s", \@para);
78  
79 0 for my $para (@para) {
80 0 ▶ if ($para->[0] eq 'blank') {
Branch: 1 branch
BranchTrueFalseTotal
if ($para->[0] eq 'blank') { } 0 0 0
81 0 push @{$self->doc_lines}, @{$para->[1]};
82 } else {
83 0 ▶ if ($para->[0] eq 'normal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($para->[0] eq "normal") 0 0 0
84 0 for (@{$para->[1]}) {
85 0 s/\n/ /g;
86 }
87 0 $para->[1] = [join("", @{$para->[1]}) . "\n"];
88 }
89 #$log->warnf("para=%s", $para);
90 0 ▶ local $Text::Wrap::columns = $ENV{COLUMNS} // 80;
Condition0%0/2
$ENV{"COLUMNS"} // 80
l!l
00
MC/DC0%0/1
$ENV{"COLUMNS"} // 80
$ENV{"COLUMNS"}
Truth table0%0/2
A
A= $ENV{"COLUMNS"}
Aresult
11
00
91 0 push @{$self->doc_lines},
92 0 Text::Wrap::wrap($indent, $indent, @{$para->[1]});
93 }
94 }
95 } else {
96 0 push @{$self->doc_lines},
97 0 map {"$indent$_"} @lines;
98 }
99 }
100  
101 4 1;
102  
103 # ABSTRACT: Provide add_doc_lines() to add text with optional text wrapping
104  
105 __END__
« Sub/To/POD.pm ↑ Summary Sub/To/Text.pm »