| 1 | package App::ansicolumn; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 253 | ▶ | use v5.14; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 253 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 253 | ▶ | use utf8; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 253 | ▶ | use List::Util qw(max min sum); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | ###################################################################### | ||||||||||||||||||||||||||||||
| 10 | # Table mode: width allocation and cell wrapping | ||||||||||||||||||||||||||||||
| 11 | ###################################################################### | ||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||
| 14 | # table_widths(\@content, $budget, $overhead, \@fixed, $floor) | ||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||
| 16 | # Decide how wide the content of each table column may be. | ||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||
| 18 | # @content width of the widest cell in each column, as given | ||||||||||||||||||||||||||||||
| 19 | # $budget width available to all columns together: the -w width | ||||||||||||||||||||||||||||||
| 20 | # minus the separators; undef when no width is requested | ||||||||||||||||||||||||||||||
| 21 | # $overhead extra width every column costs for --item-format | ||||||||||||||||||||||||||||||
| 22 | # @fixed width already decided for a column (by --cell, or by a | ||||||||||||||||||||||||||||||
| 23 | # previous round of fit_table_rows); undef for free | ||||||||||||||||||||||||||||||
| 24 | # columns (the whole argument may be undef) | ||||||||||||||||||||||||||||||
| 25 | # $floor minimum width given to a free column | ||||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||||
| 27 | # Fixed columns get their fixed width. Free columns whose widest cell | ||||||||||||||||||||||||||||||
| 28 | # fits get that width. If that does not fit the budget, the free | ||||||||||||||||||||||||||||||
| 29 | # columns share it by the water level rule: find the largest L (not | ||||||||||||||||||||||||||||||
| 30 | # below $floor) such that every free column with min(content, L) | ||||||||||||||||||||||||||||||
| 31 | # fits the budget; columns narrower than L keep their width, the | ||||||||||||||||||||||||||||||
| 32 | # others are cut to L and will be wrapped. Dividing by L leaves a | ||||||||||||||||||||||||||||||
| 33 | # remainder smaller than the number of cut columns; it goes to the | ||||||||||||||||||||||||||||||
| 34 | # cut columns one column of width each, widest content first. | ||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||
| 36 | 473 | ▶ | sub table_widths { | ||||||||||||||||||||||||||||
|
Subroutine
table_widths: called CC=15 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 37 | 473 | my($content, $budget, $overhead, $fixed, $floor) = @_; | |||||||||||||||||||||||||||||
| 38 | 473 | my @target = @$content; | |||||||||||||||||||||||||||||
| 39 | 473 | my @free; | |||||||||||||||||||||||||||||
| 40 | 473 | for my $i (keys @target) { | |||||||||||||||||||||||||||||
| 41 | 1798 | ▶ | if ($fixed and defined $fixed->[$i]) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$fixed and defined $fixed->[$i]
MC/DC100%2/2
$fixed and defined $fixed->[$i]
$fixed
defined $fixed->[$i]
Truth table100%3/3
A and B
A= $fixedB= defined $fixed->[$i]
| |||||||||||||||||||||||||||||||
| 42 | 161 | $target[$i] = $fixed->[$i]; | |||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||||
| 44 | 1637 | push @free, $i; | |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | 473 | ▶ | return \@target unless defined $budget and @free; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $budget and @free
MC/DC100%2/2
defined $budget and @free
defined $budget
@free
Truth table100%3/3
A and B
A= defined $budgetB= @free
| |||||||||||||||||||||||||||||||
| 48 | 457 | my $remain = $budget; | |||||||||||||||||||||||||||||
| 49 | $remain -= $target[$_] + $overhead | ||||||||||||||||||||||||||||||
| 50 | 457 | ▶ | for grep { $fixed and defined $fixed->[$_] } keys @target; | ||||||||||||||||||||||||||||
|
Condition100%3/3
$fixed && defined $fixed->[$_]
MC/DC100%2/2
$fixed && defined $fixed->[$_]
$fixed
defined $fixed->[$_]
Truth table100%3/3
A && B
A= $fixedB= defined $fixed->[$_]
| |||||||||||||||||||||||||||||||
| 51 | 17660 | ▶ | my $cost = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 52 | 17660 | my $level = shift; | |||||||||||||||||||||||||||||
| 53 | 17660 | sum map { min($content->[$_], $level) + $overhead } @free; | |||||||||||||||||||||||||||||
| 54 | 457 | }; | |||||||||||||||||||||||||||||
| 55 | 457 | ▶ | return \@target if $cost->(max @$content) <= $remain; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 56 | 412 | my $level = $floor; | |||||||||||||||||||||||||||||
| 57 | 412 | ▶ | for (my $l = max(@{$content}[@free]); $l > $floor; $l--) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 58 | 16791 | ▶ | if ($cost->($l) <= $remain) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 59 | 408 | $level = $l; | |||||||||||||||||||||||||||||
| 60 | 408 | last; | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||
| 63 | 412 | $target[$_] = min($content->[$_], $level) for @free; | |||||||||||||||||||||||||||||
| 64 | 412 | my $left = $remain - $cost->($level); | |||||||||||||||||||||||||||||
| 65 | 412 | ▶ | if ($left > 0) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 66 | 845 | ▶ | my @wrapped = sort { $content->[$b] <=> $content->[$a] or $a <=> $b } | ||||||||||||||||||||||||||||
|
Condition66%2/3
$content->[$b] <=> $content->[$a] || $a <=> $b
MC/DC0%0/2
$content->[$b] <=> $content->[$a] || $a <=> $b
$content->[$b] <=> $content->[$a]
$a <=> $b
Truth table66%2/3
A || B
A= $content->[$b] <=> $content->[$a]B= $a <=> $b
| |||||||||||||||||||||||||||||||
| 67 | 201 | grep { $content->[$_] > $level } @free; | |||||||||||||||||||||||||||||
| 68 | 201 | $target[$_]++ for @wrapped[0 .. min($left, scalar @wrapped) - 1]; | |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||
| 70 | 412 | \@target; | |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||
| 74 | # parse_cell_spec($spec, \@content) | ||||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||||
| 76 | # Resolve --cell specification for table mode. Entries are separated | ||||||||||||||||||||||||||||||
| 77 | # by comma and the last entry is repeated for remaining columns. | ||||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||||
| 79 | # N fixed width N | ||||||||||||||||||||||||||||||
| 80 | # <N upper bound: min(content, N) (also <=N, =N, bare = or <) | ||||||||||||||||||||||||||||||
| 81 | # +N -N relative to the natural content width (minimum 1) | ||||||||||||||||||||||||||||||
| 82 | # 0 automatic (no constraint) | ||||||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||||||
| 84 | # Returns array reference with a width or undef for each column. | ||||||||||||||||||||||||||||||
| 85 | # | ||||||||||||||||||||||||||||||
| 86 | 20 | ▶ | sub parse_cell_spec { | ||||||||||||||||||||||||||||
|
Subroutine
parse_cell_spec: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 87 | 20 | my($spec, $content) = @_; | |||||||||||||||||||||||||||||
| 88 | 20 | my @entry = split /,+/, $spec; | |||||||||||||||||||||||||||||
| 89 | 20 | my @fixed; | |||||||||||||||||||||||||||||
| 90 | 20 | for my $i (keys @$content) { | |||||||||||||||||||||||||||||
| 91 | 38 | ▶ | my $e = $entry[$i] // $entry[-1]; | ||||||||||||||||||||||||||||
|
Condition66%2/3
$entry[$i] // $entry[-1]
MC/DC0%0/2
$entry[$i] // $entry[-1]
$entry[$i]
$entry[-1]
Truth table66%2/3
A // B
A= $entry[$i]B= $entry[-1]
| |||||||||||||||||||||||||||||||
| 92 | 38 | my $w; | |||||||||||||||||||||||||||||
| 93 | 38 | ▶ | if ($e eq q(0)) { | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 94 | 9 | $w = undef; | |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||
| 96 | elsif ($e =~ /^\d+$/) { | ||||||||||||||||||||||||||||||
| 97 | 19 | $w = $e; | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | elsif ($e =~ /^[-+]\d+$/) { | ||||||||||||||||||||||||||||||
| 100 | 2 | $w = max(1, $content->[$i] + $e); | |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||
| 102 | elsif ($e =~ /^(?:<=|[<=])(\d*)$/) { | ||||||||||||||||||||||||||||||
| 103 | 7 | ▶ | $w = $1 ? min($content->[$i], $1) : $content->[$i]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||
| 105 | else { | ||||||||||||||||||||||||||||||
| 106 | 1 | die "Invalid number: $spec\n"; | |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||
| 108 | 37 | push @fixed, $w; | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||
| 110 | 19 | \@fixed; | |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 253 | ▶ | use Text::ANSI::Fold qw(:constants); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 114 | 253 | ▶ | use Text::ANSI::Fold::Util qw(ansi_width); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||||
| 117 | # table_fold($width) | ||||||||||||||||||||||||||||||
| 118 | # | ||||||||||||||||||||||||||||||
| 119 | # Text::ANSI::Fold object used to wrap table cells. Word boundary | ||||||||||||||||||||||||||||||
| 120 | # and full line-break (kinsoku) processing are on unless the user | ||||||||||||||||||||||||||||||
| 121 | # chose otherwise. Run-in characters need room, so the run-in width | ||||||||||||||||||||||||||||||
| 122 | # is reserved as margin (clamped below the width; Text::ANSI::Fold | ||||||||||||||||||||||||||||||
| 123 | # refuses margin >= width). table_margin($width) gives that margin; | ||||||||||||||||||||||||||||||
| 124 | # cells are folded at $width - margin. | ||||||||||||||||||||||||||||||
| 125 | # | ||||||||||||||||||||||||||||||
| 126 | 3583 | ▶ | sub table_lb { | ||||||||||||||||||||||||||||
|
Subroutine
table_lb: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 127 | 3583 | my $obj = shift; | |||||||||||||||||||||||||||||
| 128 | 3583 | ▶ | $obj->linebreak ? $obj->lb_flag : LINEBREAK_ALL; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||
| 131 | 3189 | ▶ | sub table_margin { | ||||||||||||||||||||||||||||
|
Subroutine
table_margin: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 132 | 3189 | my($obj, $width) = @_; | |||||||||||||||||||||||||||||
| 133 | 3189 | ▶ | ($obj->table_lb & LINEBREAK_RUNIN) ? max(0, min($obj->runin, $width - 1)) : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||
| 136 | 394 | ▶ | sub table_fold { | ||||||||||||||||||||||||||||
|
Subroutine
table_fold: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 137 | 394 | my($obj, $width) = @_; | |||||||||||||||||||||||||||||
| 138 | 394 | my $lb = $obj->table_lb; | |||||||||||||||||||||||||||||
| 139 | 394 | my $margin = $obj->table_margin($width); | |||||||||||||||||||||||||||||
| 140 | 394 | ▶ | my $fold = Text::ANSI::Fold->new( | ||||||||||||||||||||||||||||
|
Condition50%1/2
$obj->boundary || 'word'
MC/DC0%0/1
$obj->boundary || 'word'
$obj->boundary
Truth table50%1/2
A
A= $obj->boundary
| |||||||||||||||||||||||||||||||
| 141 | width => $width, | ||||||||||||||||||||||||||||||
| 142 | margin => $margin, | ||||||||||||||||||||||||||||||
| 143 | boundary => ($obj->boundary || 'word'), | ||||||||||||||||||||||||||||||
| 144 | linebreak => $lb, | ||||||||||||||||||||||||||||||
| 145 | runin => $obj->runin, | ||||||||||||||||||||||||||||||
| 146 | runout => $obj->runout, | ||||||||||||||||||||||||||||||
| 147 | ambiguous => $obj->ambiguous, | ||||||||||||||||||||||||||||||
| 148 | padchar => $obj->padchar, | ||||||||||||||||||||||||||||||
| 149 | padding => 0, | ||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||
| 151 | 394 | ▶ | $fold->configure(discard => [ 'EL' ]) if $obj->discard_el; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 152 | 394 | $fold; | |||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | # | ||||||||||||||||||||||||||||||
| 156 | # cell_lines($cell) | ||||||||||||||||||||||||||||||
| 157 | # | ||||||||||||||||||||||||||||||
| 158 | # The lines of a table cell: a LINE SEPARATOR (U+2028) in a cell | ||||||||||||||||||||||||||||||
| 159 | # breaks it into lines. An empty cell has one empty line. The cell | ||||||||||||||||||||||||||||||
| 160 | # is divided by Text::ANSI::Fold, with no width, which ends a line at | ||||||||||||||||||||||||||||||
| 161 | # the separator: colors and links that go on over it are closed at | ||||||||||||||||||||||||||||||
| 162 | # the end of the line and opened again on the next. | ||||||||||||||||||||||||||||||
| 163 | # | ||||||||||||||||||||||||||||||
| 164 | 7696 | ▶ | sub cell_lines { | ||||||||||||||||||||||||||||
|
Subroutine
cell_lines: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 165 | 7696 | my $cell = shift; | |||||||||||||||||||||||||||||
| 166 | 7696 | ▶ | return ($cell) if not defined $cell or $cell !~ /\x{2028}/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cell and $cell =~ /\x{2028}/u
MC/DC100%2/2
defined $cell and $cell =~ /\x{2028}/u
defined $cell
$cell =~ /\x{2028}/u
Truth table100%3/3
A and B
A= defined $cellB= $cell =~ /\x{2028}/u
| |||||||||||||||||||||||||||||||
| 167 | 34 | state $fold = Text::ANSI::Fold->new(width => -1); | |||||||||||||||||||||||||||||
| 168 | 34 | my @lines = map { s/\x{2028}\z//r } $fold->text($cell)->chops; | |||||||||||||||||||||||||||||
| 169 | # a separator at the end leaves an empty last line | ||||||||||||||||||||||||||||||
| 170 | 34 | ▶ | push @lines, '' if $cell =~ /\x{2028}(?:\e\[[\d;]*m|\e\]8;;[^\e]*\e\\)*\z/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 171 | 34 | @lines; | |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||
| 174 | # | ||||||||||||||||||||||||||||||
| 175 | # cell_width($cell) | ||||||||||||||||||||||||||||||
| 176 | # | ||||||||||||||||||||||||||||||
| 177 | # The width of a table cell: the width of its widest line. | ||||||||||||||||||||||||||||||
| 178 | # | ||||||||||||||||||||||||||||||
| 179 | 1193 | ▶ | sub cell_width { | ||||||||||||||||||||||||||||
|
Subroutine
cell_width: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 180 | 1193 | ▶ | max map { ansi_width($_ // '') } cell_lines(shift); | ||||||||||||||||||||||||||||
|
Condition100%2/2
$_ // ""
MC/DC100%1/1
$_ // ""
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||
| 183 | # | ||||||||||||||||||||||||||||||
| 184 | # expand_table_rows(\@rows, \@rw, \@target, \@content, \@continued, \@ow) | ||||||||||||||||||||||||||||||
| 185 | # | ||||||||||||||||||||||||||||||
| 186 | # Wrap cells wider than their target width and expand each logical | ||||||||||||||||||||||||||||||
| 187 | # row into as many physical rows as its tallest cell. A cell which | ||||||||||||||||||||||||||||||
| 188 | # has LINE SEPARATORs is broken into its lines first, and each line | ||||||||||||||||||||||||||||||
| 189 | # is wrapped on its own. Missing cell lines are filled with empty | ||||||||||||||||||||||||||||||
| 190 | # strings. Ragged rows stay ragged. | ||||||||||||||||||||||||||||||
| 191 | # \@rw holds the width of every cell of \@rows (of its widest line), | ||||||||||||||||||||||||||||||
| 192 | # and \@ow is set to the width of every cell of the rows returned, so | ||||||||||||||||||||||||||||||
| 193 | # that no cell is measured twice. | ||||||||||||||||||||||||||||||
| 194 | # When \@continued is given, $continued[row][col] is set for every | ||||||||||||||||||||||||||||||
| 195 | # cell that is the second or later line of a cell: 1 for a line of | ||||||||||||||||||||||||||||||
| 196 | # a wrapped cell, 2 for a line which starts after a LINE SEPARATOR. | ||||||||||||||||||||||||||||||
| 197 | # With an empty \@target, cells are only broken at LINE SEPARATORs. | ||||||||||||||||||||||||||||||
| 198 | # | ||||||||||||||||||||||||||||||
| 199 | # In a column that has a cell wider than the target (its widest cell, | ||||||||||||||||||||||||||||||
| 200 | # $content[col], is wider), every cell wider than the target minus the | ||||||||||||||||||||||||||||||
| 201 | # run-in margin is wrapped, as lines are in panes, so that a cell | ||||||||||||||||||||||||||||||
| 202 | # fitting in the margin is not left longer than the wrapped lines. | ||||||||||||||||||||||||||||||
| 203 | # | ||||||||||||||||||||||||||||||
| 204 | # | ||||||||||||||||||||||||||||||
| 205 | # cell_limit($width, $content): the width over which a cell is wrapped | ||||||||||||||||||||||||||||||
| 206 | # in a column of the target width whose widest cell is $content wide. | ||||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||||
| 208 | 2213 | ▶ | sub cell_limit { | ||||||||||||||||||||||||||||
|
Subroutine
cell_limit: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 209 | 2213 | my($obj, $w, $content) = @_; | |||||||||||||||||||||||||||||
| 210 | 2213 | ▶ | $content > $w ? $w - $obj->table_margin($w) : $w; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||
| 213 | # | ||||||||||||||||||||||||||||||
| 214 | # wrap_cell_line($line, $width): a line of a cell wrapped at the width, | ||||||||||||||||||||||||||||||
| 215 | # as [ \@chops, \@widths ]. Trailing spaces are removed from the | ||||||||||||||||||||||||||||||
| 216 | # chops, and so is their width. fit_table_rows wraps the same cells at | ||||||||||||||||||||||||||||||
| 217 | # the same widths again and again, so the result is kept by the object. | ||||||||||||||||||||||||||||||
| 218 | # | ||||||||||||||||||||||||||||||
| 219 | 4270 | ▶ | sub wrap_cell_line { | ||||||||||||||||||||||||||||
|
Subroutine
wrap_cell_line: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 220 | 4270 | my($obj, $line, $w) = @_; | |||||||||||||||||||||||||||||
| 221 | 4270 | ▶ | my $cache = $obj->{_cell_fold}{$w} //= { fold => $obj->table_fold($w), line => {} }; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$obj->{"_cell_fold"}{$w} //= {"fold", $obj->table_fold($w), "line", {}}
MC/DC100%1/1
$obj->{"_cell_fold"}{$w} //= {"fold", $obj->table_fold($w), "line", {}}
$obj->{"_cell_fold"}{$w}
Truth table100%2/2
A
A= $obj->{"_cell_fold"}{$w}
| |||||||||||||||||||||||||||||||
| 222 | 4270 | ▶ | $cache->{line}{$line} //= do { | ||||||||||||||||||||||||||||
|
Condition66%2/3
$cache->{"line"}{$line} //= do {
my(@c) = $cache->{"fold"}->text($line)->chops("length", \my @l);
foreach my $k (keys @c) {
$c[$k] =~ s/(\h+)((?:\e\[[\d;]*m|\e\]8;;[^\e]*\e\\)*)$/$2/u or next;
my $sp = $1;
$l[$k] = $sp =~ /^ +$/u ? $l[$k] - length($sp) : ansi_width($c[$k]);
};
@c ? [\@c, \@l] : [[""], [0]]
}
MC/DC0%0/2
$cache->{"line"}{$line} //= do {
my(@c) = $cache->{"fold"}->text($line)->chops("length", \my @l);
foreach my $k (keys @c) {
$c[$k] =~ s/(\h+)((?:\e\[[\d;]*m|\e\]8;;[^\e]*\e\\)*)$/$2/u or next;
my $sp = $1;
$l[$k] = $sp =~ /^ +$/u ? $l[$k] - length($sp) : ansi_width($c[$k]);
};
@c ? [\@c, \@l] : [[""], [0]]
}
$cache->{"line"}{$line}
do {
my(@c) = $cache->{"fold"}->text($line)->chops("length", \my @l);
foreach my $k (keys @c) {
$c[$k] =~ s/(\h+)((?:\e\[[\d;]*m|\e\]8;;[^\e]*\e\\)*)$/$2/u or next;
my $sp = $1;
$l[$k] = $sp =~ /^ +$/u ? $l[$k] - length($sp) : ansi_width($c[$k]);
};
@c ? [\@c, \@l] : [[""], [0]]
}
Truth table66%2/3
A //= B
A= $cache->{"line"}{$line}B= do {
my(@c) = $cache->{"fold"}->text($line)->chops("length", \my @l);
foreach my $k (keys @c) {
$c[$k] =~ s/(\h+)((?:\e\[[\d;]*m|\e\]8;;[^\e]*\e\\)*)$/$2/u or next;
my $sp = $1;
$l[$k] = $sp =~ /^ +$/u ? $l[$k] - length($sp) : ansi_width($c[$k]);
};
@c ? [\@c, \@l] : [[""], [0]]
}
| |||||||||||||||||||||||||||||||
| 223 | 2020 | my @c = $cache->{fold}->text($line)->chops(length => \my @l); | |||||||||||||||||||||||||||||
| 224 | 2020 | for my $k (keys @c) { | |||||||||||||||||||||||||||||
| 225 | 8866 | ▶ | $c[$k] =~ s/(\h+)((?:\e\[[\d;]*m|\e\]8;;[^\e]*\e\\)*)$/$2/ or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 226 | 1709 | my $sp = $1; | |||||||||||||||||||||||||||||
| 227 | 1709 | ▶ | $l[$k] = $sp =~ /^ +$/ ? $l[$k] - length $sp : ansi_width($c[$k]); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||
| 229 | 2020 | ▶ | @c ? [ \@c, \@l ] : [ [ '' ], [ 0 ] ]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 230 | }; | ||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||
| 233 | # | ||||||||||||||||||||||||||||||
| 234 | # column_width(\@rows, \@rw, $col, $width, $content): how wide the | ||||||||||||||||||||||||||||||
| 235 | # column comes out when it is wrapped at the width, as | ||||||||||||||||||||||||||||||
| 236 | # expand_table_rows does, without making the rows. | ||||||||||||||||||||||||||||||
| 237 | # | ||||||||||||||||||||||||||||||
| 238 | 55 | ▶ | sub column_width { | ||||||||||||||||||||||||||||
|
Subroutine
column_width: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 239 | 55 | my($obj, $rows, $rw, $i, $w, $content) = @_; | |||||||||||||||||||||||||||||
| 240 | 55 | my $limit = $obj->cell_limit($w, $content); | |||||||||||||||||||||||||||||
| 241 | max 0, map { | ||||||||||||||||||||||||||||||
| 242 | 55 | my $r = $_; | |||||||||||||||||||||||||||||
| 243 | 150 | my @lines = cell_lines($rows->[$r][$i]); | |||||||||||||||||||||||||||||
| 244 | map { | ||||||||||||||||||||||||||||||
| 245 | 150 | ▶ | my $lw = @lines > 1 ? ansi_width($_ // '') : $rw->[$r][$i] // 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$_ // ""
$rw->[$r][$i] // 0
MC/DC0%0/1
$_ // ""
$_
MC/DC0%0/1
$rw->[$r][$i] // 0
$rw->[$r][$i]
Truth table50%1/2
A
A= $_
Truth table50%1/2
A
A= $rw->[$r][$i]
| |||||||||||||||||||||||||||||||
| 246 | 152 | ▶ | $lw > $limit ? max(@{$obj->wrap_cell_line($_, $w)->[1]}) : $lw; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 247 | } @lines; | ||||||||||||||||||||||||||||||
| 248 | } keys @$rows; | ||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||
| 251 | 577 | ▶ | sub expand_table_rows { | ||||||||||||||||||||||||||||
|
Subroutine
expand_table_rows: called CC=16 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 252 | 577 | my($obj, $rows, $rw, $target, $content, $continued, $ow) = @_; | |||||||||||||||||||||||||||||
| 253 | 577 | ▶ | @$continued = () if $continued; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 254 | 577 | @$ow = (); | |||||||||||||||||||||||||||||
| 255 | my @limit = map { | ||||||||||||||||||||||||||||||
| 256 | 577 | my($i, $w) = ($_, $target->[$_]); | |||||||||||||||||||||||||||||
| 257 | 2158 | ▶ | defined $w ? $obj->cell_limit($w, $content->[$i]) : undef; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 258 | } keys @$target; | ||||||||||||||||||||||||||||||
| 259 | 577 | my @out; | |||||||||||||||||||||||||||||
| 260 | 577 | for my $r (keys @$rows) { | |||||||||||||||||||||||||||||
| 261 | 1641 | my $row = $rows->[$r]; | |||||||||||||||||||||||||||||
| 262 | 1641 | my @widths; | |||||||||||||||||||||||||||||
| 263 | my @kinds; | ||||||||||||||||||||||||||||||
| 264 | my @cells = map { | ||||||||||||||||||||||||||||||
| 265 | 1641 | my($cell, $w, $cw) = ($row->[$_], $target->[$_], $rw->[$r][$_]); | |||||||||||||||||||||||||||||
| 266 | 6353 | my @lines = cell_lines($cell); | |||||||||||||||||||||||||||||
| 267 | 6353 | my(@chops, @length, @kind); | |||||||||||||||||||||||||||||
| 268 | 6353 | for my $n (keys @lines) { | |||||||||||||||||||||||||||||
| 269 | 6375 | my $line = $lines[$n]; | |||||||||||||||||||||||||||||
| 270 | 6375 | ▶ | my $lw = @lines > 1 ? ansi_width($line // '') : $cw; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$line // ""
MC/DC0%0/1
$line // ""
$line
Truth table50%1/2
A
A= $line
| |||||||||||||||||||||||||||||||
| 271 | 6375 | my(@c, @l); | |||||||||||||||||||||||||||||
| 272 | 6375 | ▶ | if (defined $w and $lw > $limit[$_]) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $w and $lw > $limit[$_]
MC/DC100%2/2
defined $w and $lw > $limit[$_]
defined $w
$lw > $limit[$_]
Truth table100%3/3
A and B
A= defined $wB= $lw > $limit[$_]
| |||||||||||||||||||||||||||||||
| 273 | 4149 | my $wrapped = $obj->wrap_cell_line($line, $w); | |||||||||||||||||||||||||||||
| 274 | 4149 | @c = @{$wrapped->[0]}; | |||||||||||||||||||||||||||||
| 275 | 4149 | @l = @{$wrapped->[1]}; | |||||||||||||||||||||||||||||
| 276 | } else { | ||||||||||||||||||||||||||||||
| 277 | 2226 | @c = ($line); | |||||||||||||||||||||||||||||
| 278 | 2226 | @l = ($lw); | |||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||
| 280 | 6375 | ▶ | push @kind, ($n ? 2 : 0), (1) x $#c; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 281 | 6375 | push @chops, @c; | |||||||||||||||||||||||||||||
| 282 | 6375 | push @length, @l; | |||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||
| 284 | 6353 | $widths[$_] = \@length; | |||||||||||||||||||||||||||||
| 285 | 6353 | $kinds[$_] = \@kind; | |||||||||||||||||||||||||||||
| 286 | 6353 | \@chops; | |||||||||||||||||||||||||||||
| 287 | } keys @$row; | ||||||||||||||||||||||||||||||
| 288 | 1641 | my $height = max(1, map { int @$_ } @cells); | |||||||||||||||||||||||||||||
| 289 | 1641 | for my $k (0 .. $height - 1) { | |||||||||||||||||||||||||||||
| 290 | 6787 | ▶ | push @out, [ map { $_->[$k] // '' } @cells ]; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$_->[$k] // ""
MC/DC100%1/1
$_->[$k] // ""
$_->[$k]
Truth table100%2/2
A
A= $_->[$k]
| |||||||||||||||||||||||||||||||
| 291 | 6787 | ▶ | push @$ow, [ map { $_->[$k] // 0 } @widths ]; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$_->[$k] // 0
MC/DC100%1/1
$_->[$k] // 0
$_->[$k]
Truth table100%2/2
A
A= $_->[$k]
| |||||||||||||||||||||||||||||||
| 292 | 6787 | ▶ | next unless $continued and $k; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$continued and $k
MC/DC100%2/2
$continued and $k
$continued
$k
Truth table100%3/3
A and B
A= $continuedB= $k
| |||||||||||||||||||||||||||||||
| 293 | 1088 | $continued->[$#out][$_] = $kinds[$_][$k] for grep { defined $cells[$_][$k] } keys @cells; | |||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||
| 296 | 577 | @out; | |||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | # | ||||||||||||||||||||||||||||||
| 300 | # fit_table_rows(\@rows, \@rw, \@content, $budget, $overhead, \@fixed, $floor, \@continued, \@ow) | ||||||||||||||||||||||||||||||
| 301 | # | ||||||||||||||||||||||||||||||
| 302 | # Wrap the table into the budget. Each round: | ||||||||||||||||||||||||||||||
| 303 | # | ||||||||||||||||||||||||||||||
| 304 | # 1. table_widths() decides the width of every column. | ||||||||||||||||||||||||||||||
| 305 | # 2. expand_table_rows() wraps the cells to those widths. | ||||||||||||||||||||||||||||||
| 306 | # 3. Measure how wide each wrapped column actually came out. | ||||||||||||||||||||||||||||||
| 307 | # 4. A wrapped column that left two or more columns of its width | ||||||||||||||||||||||||||||||
| 308 | # unused (its lines broke at word or kinsoku boundaries before | ||||||||||||||||||||||||||||||
| 309 | # the limit) is fixed at the measured width. Its wrapped lines | ||||||||||||||||||||||||||||||
| 310 | # are kept as they are. | ||||||||||||||||||||||||||||||
| 311 | # 5. If any column was fixed, go back to 1: the fixed column now | ||||||||||||||||||||||||||||||
| 312 | # costs only what it uses, so the remaining wrapped columns get | ||||||||||||||||||||||||||||||
| 313 | # more. Otherwise stop. | ||||||||||||||||||||||||||||||
| 314 | # | ||||||||||||||||||||||||||||||
| 315 | # One column short is not "unused": a double-width character cannot | ||||||||||||||||||||||||||||||
| 316 | # fill an odd width. Each round fixes at least one more column or | ||||||||||||||||||||||||||||||
| 317 | # stops, so the loop ends within (number of columns + 1) rounds. | ||||||||||||||||||||||||||||||
| 318 | # | ||||||||||||||||||||||||||||||
| 319 | # Returns the expanded rows. \@rw, \@continued and \@ow are passed | ||||||||||||||||||||||||||||||
| 320 | # to expand_table_rows(); \@continued and \@ow describe the rows | ||||||||||||||||||||||||||||||
| 321 | # returned. | ||||||||||||||||||||||||||||||
| 322 | # | ||||||||||||||||||||||||||||||
| 323 | # The widths are decided on the target widths, but a wrapped column | ||||||||||||||||||||||||||||||
| 324 | # often comes out narrower than its target: the run-in margin is kept | ||||||||||||||||||||||||||||||
| 325 | # free in every wrapped column and is used only when a run-in | ||||||||||||||||||||||||||||||
| 326 | # character goes there, and lines break at word boundaries before the | ||||||||||||||||||||||||||||||
| 327 | # limit. So the table is fit again with the width left unused added | ||||||||||||||||||||||||||||||
| 328 | # to the budget, as long as the result still fits the real budget and | ||||||||||||||||||||||||||||||
| 329 | # comes out wider. | ||||||||||||||||||||||||||||||
| 330 | # | ||||||||||||||||||||||||||||||
| 331 | # A larger budget raises every wrapped column at once, and the table | ||||||||||||||||||||||||||||||
| 332 | # can come out several columns wider by one more column of budget, | ||||||||||||||||||||||||||||||
| 333 | # over the budget. What is still left is then given to the wrapped | ||||||||||||||||||||||||||||||
| 334 | # columns one by one, widest content first: a column is wrapped at a | ||||||||||||||||||||||||||||||
| 335 | # width larger by one, two, and so on up to what is left, the first | ||||||||||||||||||||||||||||||
| 336 | # that makes it wider within the budget is taken, and so again until | ||||||||||||||||||||||||||||||
| 337 | # none does. How wide a column comes out depends on its own width | ||||||||||||||||||||||||||||||
| 338 | # only, so a column is measured alone, and a column that cannot be | ||||||||||||||||||||||||||||||
| 339 | # widened cannot be later, with less left. | ||||||||||||||||||||||||||||||
| 340 | # | ||||||||||||||||||||||||||||||
| 341 | # Only the widths are looked for; the rows are made once at the end. | ||||||||||||||||||||||||||||||
| 342 | # | ||||||||||||||||||||||||||||||
| 343 | 108 | ▶ | sub fit_table_rows { | ||||||||||||||||||||||||||||
|
Subroutine
fit_table_rows: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 344 | 108 | my($obj, $rows, $rw, $content, $budget, $overhead, $fixed, $floor, $continued, $ow) = @_; | |||||||||||||||||||||||||||||
| 345 | 108 | ▶ | my $is_fixed = sub { $fixed and defined $fixed->[$_[0]] }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 346 | # the width of the table, from the widths of the columns | ||||||||||||||||||||||||||||||
| 347 | 348 | ▶ | my $used = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 348 | 348 | my $cw = shift; | |||||||||||||||||||||||||||||
| 349 | 348 | ▶ | sum map { ($is_fixed->($_) ? $fixed->[$_] : $cw->[$_]) + $overhead } keys @$content; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 350 | 108 | }; | |||||||||||||||||||||||||||||
| 351 | # fit into a budget: the widths wrapped at, and those come out | ||||||||||||||||||||||||||||||
| 352 | 348 | ▶ | my $fit = sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||
| 353 | 348 | my $b = shift; | |||||||||||||||||||||||||||||
| 354 | 348 | my(@w, @t); | |||||||||||||||||||||||||||||
| 355 | 348 | $obj->fit_table_rounds($rows, $rw, $content, $b, $overhead, $fixed, $floor, undef, \@w, \@t); | |||||||||||||||||||||||||||||
| 356 | 348 | ▶ | my @cw = map { my $i = $_; max 0, map { $_->[$i] // 0 } @w } keys @$content; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$_->[$i] // 0
MC/DC0%0/1
$_->[$i] // 0
$_->[$i]
Truth table50%1/2
A
A= $_->[$i]
| |||||||||||||||||||||||||||||||
| 357 | 348 | { target => \@t, cw => \@cw, used => $used->(\@cw) }; | |||||||||||||||||||||||||||||
| 358 | 108 | }; | |||||||||||||||||||||||||||||
| 359 | 108 | my $best = $fit->($budget); | |||||||||||||||||||||||||||||
| 360 | 108 | ▶ | if (defined $budget) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 361 | 96 | my $try = $budget; | |||||||||||||||||||||||||||||
| 362 | # each round makes the table wider within the budget, or stops | ||||||||||||||||||||||||||||||
| 363 | 96 | ▶ | while ((my $left = $budget - $best->{used}) > 0) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 364 | 140 | my $next; | |||||||||||||||||||||||||||||
| 365 | 140 | ▶ | for (my $t = $try + $left; $t > $try; $t--) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 366 | 240 | my $r = $fit->($t); | |||||||||||||||||||||||||||||
| 367 | 240 | ▶ | next if $r->{used} > $budget; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 368 | 109 | ▶ | ($next, $try) = ($r, $t) if $r->{used} > $best->{used}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 369 | 109 | last; | |||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||
| 371 | 140 | ▶ | last unless $next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 372 | 98 | $best = $next; | |||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||
| 374 | 96 | my($t, $cw, $u) = @{$best}{qw(target cw used)}; | |||||||||||||||||||||||||||||
| 375 | 96 | ▶ | for my $i (sort { $content->[$b] <=> $content->[$a] or $a <=> $b } | ||||||||||||||||||||||||||||
|
Condition66%2/3
$content->[$b] <=> $content->[$a] || $a <=> $b
MC/DC0%0/2
$content->[$b] <=> $content->[$a] || $a <=> $b
$content->[$b] <=> $content->[$a]
$a <=> $b
Truth table66%2/3
A || B
A= $content->[$b] <=> $content->[$a]B= $a <=> $b
| |||||||||||||||||||||||||||||||
| 376 | 378 | grep { not $is_fixed->($_) } keys @$content) { | |||||||||||||||||||||||||||||
| 377 | WIDEN: | ||||||||||||||||||||||||||||||
| 378 | 376 | ▶ | while ((my $left = $budget - $u) > 0 and $content->[$i] > $t->[$i]) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
(my $left = $budget - $u) > 0 and $content->[$i] > $t->[$i]
MC/DC100%2/2
(my $left = $budget - $u) > 0 and $content->[$i] > $t->[$i]
(my $left = $budget - $u) > 0
$content->[$i] > $t->[$i]
Truth table100%3/3
A and B
A= (my $left = $budget - $u) > 0B= $content->[$i] > $t->[$i]
| |||||||||||||||||||||||||||||||
| 379 | 46 | for my $d (1 .. $left) { | |||||||||||||||||||||||||||||
| 380 | 55 | my $m = $obj->column_width($rows, $rw, $i, $t->[$i] + $d, $content->[$i]); | |||||||||||||||||||||||||||||
| 381 | 55 | ▶ | next if $m <= $cw->[$i] or $u + $m - $cw->[$i] > $budget; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$m <= $cw->[$i] or $u + $m - $cw->[$i] > $budget
MC/DC100%2/2
$m <= $cw->[$i] or $u + $m - $cw->[$i] > $budget
$m <= $cw->[$i]
$u + $m - $cw->[$i] > $budget
Truth table100%3/3
A or B
A= $m <= $cw->[$i]B= $u + $m - $cw->[$i] > $budget
| |||||||||||||||||||||||||||||||
| 382 | 25 | $u += $m - $cw->[$i]; | |||||||||||||||||||||||||||||
| 383 | 25 | $cw->[$i] = $m; | |||||||||||||||||||||||||||||
| 384 | 25 | $t->[$i] += $d; | |||||||||||||||||||||||||||||
| 385 | 25 | next WIDEN; | |||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||
| 387 | 21 | last; | |||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||
| 391 | 108 | $obj->expand_table_rows($rows, $rw, $best->{target}, $content, $continued, $ow); | |||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||
| 394 | # | ||||||||||||||||||||||||||||||
| 395 | # fit_table_rounds(..., \@width): the rounds of fit_table_rows | ||||||||||||||||||||||||||||||
| 396 | # described above, for one budget. Arguments are those of | ||||||||||||||||||||||||||||||
| 397 | # fit_table_rows, and \@width is set to the widths the columns were | ||||||||||||||||||||||||||||||
| 398 | # wrapped at. | ||||||||||||||||||||||||||||||
| 399 | # | ||||||||||||||||||||||||||||||
| 400 | 348 | ▶ | sub fit_table_rounds { | ||||||||||||||||||||||||||||
|
Subroutine
fit_table_rounds: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 401 | 348 | my($obj, $rows, $rw, $content, $budget, $overhead, $fixed, $floor, $continued, $ow, $wout) = @_; | |||||||||||||||||||||||||||||
| 402 | 348 | ▶ | my @fix = $fixed ? @$fixed : (); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 403 | 348 | my @wrap; # width each column was wrapped at | |||||||||||||||||||||||||||||
| 404 | my @out; | ||||||||||||||||||||||||||||||
| 405 | 348 | while (1) { | |||||||||||||||||||||||||||||
| 406 | 460 | my $target = table_widths($content, $budget, $overhead, \@fix, $floor); | |||||||||||||||||||||||||||||
| 407 | 460 | ▶ | my @width = map { $wrap[$_] // $target->[$_] } keys @$content; | ||||||||||||||||||||||||||||
|
Condition66%2/3
$wrap[$_] // $target->[$_]
MC/DC0%0/2
$wrap[$_] // $target->[$_]
$wrap[$_]
$target->[$_]
Truth table66%2/3
A // B
A= $wrap[$_]B= $target->[$_]
| |||||||||||||||||||||||||||||||
| 408 | 460 | @out = $obj->expand_table_rows($rows, $rw, \@width, $content, $continued, $ow); | |||||||||||||||||||||||||||||
| 409 | 460 | ▶ | @$wout = @width if $wout; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 410 | 460 | my $changed = 0; | |||||||||||||||||||||||||||||
| 411 | 460 | for my $i (keys @$content) { | |||||||||||||||||||||||||||||
| 412 | 1758 | ▶ | next if defined $fix[$i] or $content->[$i] <= $target->[$i]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $fix[$i] or $content->[$i] <= $target->[$i]
MC/DC100%2/2
defined $fix[$i] or $content->[$i] <= $target->[$i]
defined $fix[$i]
$content->[$i] <= $target->[$i]
Truth table100%3/3
A or B
A= defined $fix[$i]B= $content->[$i] <= $target->[$i]
| |||||||||||||||||||||||||||||||
| 413 | 1146 | my $usable = $target->[$i] - $obj->table_margin($target->[$i]); | |||||||||||||||||||||||||||||
| 414 | 1146 | ▶ | my $measured = max 0, map { $_->[$i] // 0 } @$ow; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$_->[$i] // 0
MC/DC0%0/1
$_->[$i] // 0
$_->[$i]
Truth table50%1/2
A
A= $_->[$i]
| |||||||||||||||||||||||||||||||
| 415 | 1146 | ▶ | next if $measured >= $usable - 1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 416 | 114 | $fix[$i] = $measured; | |||||||||||||||||||||||||||||
| 417 | 114 | $wrap[$i] = $target->[$i]; | |||||||||||||||||||||||||||||
| 418 | 114 | $changed++; | |||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||
| 420 | 460 | ▶ | last unless $changed; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||
| 422 | 348 | @out; | |||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||
| 425 | 253 | 1; | |||||||||||||||||||||||||||||