| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table0%0/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my @lines = map { $_ . (/\n\z/s ? "" : "\n") } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | map {/\n/ ? split /\n/ : $_} @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($wrap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (defined($start) && $type ne 'blank') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $start and $type ne "blank"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | push @para, [$type, [@lines[$start..$i-1]]]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | undef $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $start //= $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$start //= $i
MC/DC0%0/2
$start //= $i
$start
$i
Truth table0%0/3
A //= B
A= $startB= $i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
not $i or $type eq "verbatim" or @para and $para[-1][0] eq "blank"
not $i or $type eq "verbatim"
@para and $para[-1][0] eq "blank"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | (@para && $para[-1][0] eq 'blank'))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if (defined($start) && $type ne 'verbatim') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $start and $type ne "verbatim"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | push @para, [$type, [@lines[$start..$i-1]]]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | undef $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $start //= $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$start //= $i
MC/DC0%0/2
$start //= $i
$start
$i
Truth table0%0/3
A //= B
A= $startB= $i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $type = 'verbatim'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (defined($start) && $type ne 'normal') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $start and $type ne "normal"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | push @para, [$type, [@lines[$start..$i-1]]]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | undef $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $start //= $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$start //= $i
MC/DC0%0/2
$start //= $i
$start
$i
Truth table0%0/3
A //= B
A= $startB= $i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@para and $para[-1][0] eq $type
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | push @{$self->doc_lines}, @{$para->[1]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($para->[0] eq 'normal') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$ENV{"COLUMNS"} // 80
$ENV{"COLUMNS"}
Truth table0%0/2
A
A= $ENV{"COLUMNS"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||