lib/App/ansicolumn.pm

filter: Statementstmt 92.5% 703 / 760 Branchbran 80.2% 228 / 284 Conditioncond 69.6% 142 / 204 MC/DCmcdc 45.2% 52 / 115 Subroutinesub 86.2% 69 / 80 Podpod 0.0% 0 / 16 totaltotal 81.8% 1194 / 1459 CC 248 SCAR 30.8
CC
248
Cov
86%
table_out
61.7
setup_options
47.6
parallel_out
16.9
CRAP 21.7
↑ Summary lib/App/ansicolumn/Table.pm »
1 package App::ansicolumn;
2  
3 253 our $VERSION = "1.69";
4  
5 253 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 253 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 253 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 253 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 253 ▶use open IO => 'utf8', ':std';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 253 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 253 ▶use Getopt::EX::Long qw(:DEFAULT Configure ExConfigure);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 253 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 253 ▶use List::Util qw(max sum min any);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 253 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 253 ▶use Text::ANSI::Fold qw(ansi_fold);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 253 ▶use Text::ANSI::Fold::Util qw(ansi_width);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 253 ▶use Text::ANSI::Printf qw(ansi_printf ansi_sprintf);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 253 ▶use App::ansicolumn::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 253 ▶use App::ansicolumn::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 253 ▶use App::ansicolumn::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 253 ▶use App::ansicolumn::Border;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 253 ▶use Getopt::EX::RPN qw(rpn_calc);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 253 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 253 our @EXPORT_OK = qw(ansicolumn);
27  
28 # --intact: what joins the lines to be kept intact into one line
29 # (UNIT SEPARATOR, for now)
30 253 our $INTACT_SEP = "\x1F";
31  
32 251 ▶sub ansicolumn {
Subroutine ansicolumn: called CC=1 SCAR=0.0
Pod undocumented
33 251 __PACKAGE__->new->perform(@_);
34 }
35  
36 253 my %DEFAULT_COLORMAP = (
37 BORDER => '',
38 BORDER_LABEL => '',
39 TEXT => '',
40 );
41  
42 253 ▶use Getopt::EX::Hashed 1.0701; {
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 253 Getopt::EX::Hashed->configure( DEFAULT => [ is => 'rw' ] );
45  
46 253 has debug => ' ' ;
47 253 has help => ' h ' ;
48 253 has version => ' v ' ;
49 253 has width => ' =s w c ' ;
50 253 has fillrows => ' x ' ;
51 253 has table => ' t ' ;
52 253 has table_columns_limit => ' =i l ' , default => -1 ;
53 253 has table_align => ' ! A ' ;
54 253 has table_tabs => ' + T ' ;
55 253 has table_right => ' =s R ' , default => '' ;
56 253 has table_center => ' =s ' , default => '' ;
57 253 has item_format => ' =s ' , default => '' ;
58 253 has table_wrap_mark => ' =s ' , default => '' ;
59 253 has table_cell_mark => ' =s ' , default => '' ;
60 253 has table_head => ' =i ' , default => 0 ;
61 253 has table_remove => ' =s K ' , default => '' ;
62 253 has table_squeeze => ' ! ' ;
63 253 has padding => ' ! ' ;
64 253 has separator => ' =s s ' , default => ' ' ;
65 253 has regex_sep => ' r ' ;
66 253 has output_separator => ' =s o ' , default => ' ' ;
67 253 has document => ' ! D ' ;
68 253 has parallel => ' ! V ' ;
69 253 has filename => ' ! H ' ;
70 253 has filename_format => ' =s ' , default => ': %s';
71 253 has ignore_empty => ' ! I ' , default => 0 ;
72 253 has pages => ' ! ' ;
73 253 has up => ' :s U ' ;
74 253 has page => ' :i P ' , min => 0;
75 0 ▶ has no_page => ' ' , action => sub { $_->page = undef } ;
Subroutine __ANON__: not called CC=1 SCAR=1.2
76 253 has pane => ' =s C ' , default => 0 ;
77 253 has cell => ' =s X ' ;
78 253 has pane_width => ' =s S pw ' ;
79 253 has widen => ' ! W ' ;
80 253 has paragraph => ' ! p ' ;
81 253 has height => ' =s ' , default => 0 ;
82 253 has column_unit => ' =i cu ' , min => 1, default => 8 ;
83 253 has margin => ' =i ' , min => 0, default => 1 ;
84 253 has tabstop => ' =i ' , min => 1, default => 8 ;
85 253 has tabhead => ' =s ' ;
86 253 has tabspace => ' =s ' ;
87 253 has tabstyle => ' :s ts ' ;
88 253 has ignore_space => ' ! is ' , default => 1 ;
89 253 has linestyle => ' =s ls ' , default => '' ;
90 253 has boundary => ' =s ' , default => '' ;
91 253 has linebreak => ' =s lb ' , default => '' ;
92 253 has runin => ' =i ' , min => 0, default => 2 ;
93 253 has runout => ' =i ' , min => 0, default => 2 ;
94 253 has runlen => ' =i ' ;
95 253 has pagebreak => ' ! ' , default => 1 ;
96 253 has intact => ' ! ' ;
97 0 ▶ has border => ' :s ' ; has B => '' , action => sub { $_->border = '' } ;
Subroutine __ANON__: not called CC=1 SCAR=0.4
98 4 ▶ has no_border => ' ' , action => sub { $_->border = 'none' } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
99 253 has border_style => ' =s bs ' , default => 'box' ;
100 253 has label => ' =s% ' , default => {} ;
101 253 has page_label => ' =s% ' , default => {} ;
102 253 has mark => ' =s% ' , default => {} ;
103 253 has white_space => ' ! ' , default => 2 ;
104 253 has isolation => ' ! ' , default => 2 ;
105 0 ▶ has fillup => ' :s ' ; has F => '' , action => sub { $_->fillup = '' } ;
Subroutine __ANON__: not called CC=1 SCAR=0.4
106 253 has fillup_str => ' :s ' , default => '' ;
107 253 has ambiguous => ' =s ' , default => 'narrow' ;
108 253 has discard_el => ' ! ' , default => 1 ;
109 253 has padchar => ' =s ' , default => ' ' ;
110 253 has colormap => ' =s@ cm ' , default => [] ;
111 253 has factotum => ' =s@ ' , default => [] ;
112 253 has highlight => ' :s hi ' , action => \&_highlight ;
113 1 ▶ has no_highlight => ' ' , action => sub { $_->highlight = undef } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
114 4 ▶ has no_hi => ' ' , action => sub { $_->highlight = undef } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
115  
116 253 has '+boundary' => any => [ qw(none word space) ] ;
117 253 has '+linestyle' => any => [ qw(none wordwrap wrap truncate) ] ;
118 253 has '+fillup' => any => [ qw(pane page none), '' ] ;
119 253 has '+ambiguous' => any => [ qw(wide narrow) ] ;
120  
121 # --2up .. --9up
122 0 ▶ my $nup = sub { $_[0] =~ /^(\d+)/ and $_->up = $1 } ;
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^(\d+)/u and $_->up = $1 0 0 0
123 253 for my $n (2..9) {
124 2024 has "${n}up" => '', action => $nup;
125 }
126  
127 # for run-time use
128 253 has span => ;
129 253 has panes => ;
130 253 has border_height => ;
131 253 has current_page => ;
132 253 has _bl => ;
133 253 has _pbl => ;
134 253 has _mk => ;
135 253 has _total_panes => ;
136 253 has _cell_fold => ; # cells wrapped by the table mode, by width
137 253 has _total_pages => ;
138  
139 253 Getopt::EX::Hashed->configure( DEFAULT => [] );
140  
141 0 ▶ has '+help' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
142 0 pod2usage
143 -verbose => 99,
144 -sections => [ qw(SYNOPSIS VERSION) ];
145 253 };
146  
147 0 ▶ has '+version' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
148 0 say "Version: $VERSION";
149 0 exit;
150 253 };
151  
152 ### RPN calc for --height, --width, --pane, --up, --pane-width
153 282 ▶ has [ qw(+height +width +pane +up +pane_width) ] => sub {
Subroutine __ANON__: called CC=4 SCAR=20.9
154 282 my $obj = $_;
155 282 my($name, $val) = @_;
156 282 ▶ $obj->$name = $val !~ /\D/ ? $val : do {
Branch: 1 branch
BranchTrueFalseTotal
!($val =~ /\D/u) ? : 282 0 282
157 0 ▶ my $init = $name =~ /height/ ? $obj->term_height : $obj->term_width;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /height/u ? : 0 0 0
158 0 ▶ rpn_calc($init, $val) // die "$val: invalid $name.\n";
Condition0%0/2
rpn_calc($init, $val) // die("${val}: invalid $name.\n")
l!l
00
MC/DC0%0/1
rpn_calc($init, $val) // die("${val}: invalid $name.\n")
rpn_calc($init, $val)
Truth table0%0/2
A
A= rpn_calc($init, $val)
Aresult
11
00
159 };
160 253 };
161  
162 ### --ambiguous=wide
163 0 ▶ has '+ambiguous' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
164 0 ▶ if ($_[1] eq 'wide') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] eq "wide") 0 0 0
165 0 $Text::VisualWidth::PP::EastAsian = 1;
166 0 Text::ANSI::Fold->configure(ambiguous => 'wide');
167 }
168 253 };
169  
170 ### --runlen
171 0 ▶ has '+runlen' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
172 0 $_->runin = $_->runout = $_[1];
173 253 };
174  
175 ### --tabstop, --tabstyle
176 0 ▶ has [ qw(+tabstop +tabstyle) ] => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
177 0 my($name, $val) = map "$_", @_;
178 0 ▶ if ($val eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq "") 0 0 0
179 0 list_tabstyle();
180 0 exit;
181 }
182 0 Text::ANSI::Fold->configure($name => $val);
183 253 };
184  
185 ### --tabhead, --tabspace
186 253 ▶ use charnames ':loose';
Subroutine BEGIN: called CC=1 SCAR=0.0
187 0 ▶ has [ qw(+tabhead +tabspace) ] => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
188 0 my($name, $c) = map "$_", @_;
189 0 ▶ $c = charnames::string_vianame($c) || die "$c: invalid name\n"
Branch: 1 branch
BranchTrueFalseTotal
if length $c > 1 0 0 0
Condition0%0/2
charnames::string_vianame($c) || die("${c}: invalid name\n")
l!l
00
MC/DC0%0/1
charnames::string_vianame($c) || die("${c}: invalid name\n")
charnames::string_vianame($c)
Truth table0%0/2
A
A= charnames::string_vianame($c)
Aresult
11
00
190 if length($c) > 1;
191 0 Text::ANSI::Fold->configure($name => $c);
192 253 };
193  
194 ### -A
195 3 ▶ has '+table_align' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
196 3 ▶ if ($_->table_align = $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->table_align = $_[1]) 3 0 3
197 3 $_->table = $_[1];
198 }
199 253 };
200 ### -T, -TT
201 1 ▶ has '+table_tabs' => sub {
Subroutine __ANON__: called CC=3 SCAR=15.1
202 # incremental behavior
203 1 $_->table_tabs += $_[1];
204 1 ▶ if ($_->table_tabs == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_->table_tabs == 1) { } 1 0 1
elsif ($_->table_tabs == 2) { } 0 0 0
205 # enable -t and -A
206 1 $_->table = $_->table_align = $_[1];
207 } elsif ($_->table_tabs == 2) {
208 # set -rs '\t+'
209 0 $_->regex_sep = 1;
210 0 $_->separator = '\\t+';
211 }
212 253 };
213  
214 253 has TERM_SIZE => ;
215 253 has COLORHASH => default => { %DEFAULT_COLORMAP };
216 253 has COLORLIST => default => [];
217 253 has COLOR => ;
218 253 has BORDER => ;
219  
220 253 ▶} no Getopt::EX::Hashed;
Subroutine BEGIN: called CC=1 SCAR=0.0
221  
222 0 ▶sub list_tabstyle {
Subroutine list_tabstyle: not called CC=2 SCAR=17.9
Pod undocumented
223 0 my %style = %Text::ANSI::Fold::TABSTYLE;
224 0 my $max = max map length, keys %style;
225 0 for my $name (sort keys %style) {
226 0 my($head, $space) = @{$style{$name}};
227 0 printf "%*s %s%s\n", $max, $name, $head, $space x 7;
228 }
229 }
230  
231 # --highlight[=NAME]: the value is optional, so Getopt::Long takes
232 # the word after the option for it. When the word is a file and not
233 # the name of a highlighter, it is given back to be read as a file.
234 23 ▶sub _highlight {
Subroutine _highlight: called CC=4 SCAR=13.9
235 23 my $obj = $_;
236 23 my($name, $value) = @_;
237 23 ▶ if ($value ne '' and not _highlighter($value) and -e $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value ne "" and not _highlighter($value) and -e $value) 3 20 23
Condition100%6/6
$value ne "" and not _highlighter($value) and -e $value
!ll&&!rl&&r
1913
$value ne "" and not _highlighter($value)
!ll&&!rl&&r
1094
MC/DC100%3/3
$value ne "" and not _highlighter($value) and -e $value
$value ne "" not _highlighter($value) -e $value
Truth table100%4/4
A and not(B) and C
A= $value ne ""B= not _highlighter($value)C= -e $value
ABCresult
0XX0
10X0
1100
1111
238 3 unshift @ARGV, $value;
239 3 $value = '';
240 }
241 23 $obj->highlight = $value;
242 }
243  
244 # The name of a highlighter of Text::ANSI::Highlight, or its short name
245 13 ▶sub _highlighter {
Subroutine _highlighter: called CC=2 SCAR=7.0
246 13 my $name = shift;
247 13 ▶ eval { require Text::ANSI::Highlight; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Text::ANSI::Highlight; 1 } } and defined "Text::ANSI::Highlight"->highlighter($name) 13 0 13
248 and defined Text::ANSI::Highlight->highlighter($name);
249 }
250  
251 251 ▶sub perform {
Subroutine perform: called CC=14 SCAR=26.7
Pod undocumented
252 251 my $obj = shift;
253 251 local @ARGV = decode_argv(@_);
254 251 ExConfigure BASECLASS => [ __PACKAGE__, "Getopt::EX" ];
255 251 Configure qw(bundling no_auto_abbrev no_ignore_case);
256 251 ▶ $obj->getopt || pod2usage(2);
Branch: 1 branch
BranchTrueFalseTotal
$obj->getopt or pod2usage(2) 251 0 251
257  
258 251 $obj->setup_options;
259  
260 # --mark: an unknown name is an error, with or without a label
261 251 $obj->_marks;
262  
263 # The files are read through IO::Factotum when it is loaded
264 # (read_files), and this is the only place which knows what it
265 # reads them through.
266 #
267 # --factotum: converters of IO::Factotum, by their names.
268 250 my @names = map { split /,/ } @{$obj->factotum};
269 250 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 4 246 250
270 4 ▶ eval { require IO::Factotum; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require IO::Factotum; 1 } } or die "--factotum requires IO::Factotum. " 4 0 4
271 or die "--factotum requires IO::Factotum.\n";
272 4 IO::Factotum::load(@names);
273 }
274 # --highlight[=NAME]: Text::ANSI::Highlight::IO gives the
275 # highlighter of the name to IO::Factotum, the default one without
276 # the name.
277 249 ▶ if (defined(my $name = $obj->highlight)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $obj->highlight)) 20 229 249
278 20 ▶ eval { require Text::ANSI::Highlight::IO; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Text::ANSI::Highlight::IO; 1 } } or die "--highlight requires Text::ANSI::Highlight::IO. " 20 0 20
279 or die "--highlight requires Text::ANSI::Highlight::IO.\n";
280 20 ▶ eval { Text::ANSI::Highlight::IO->setup($name eq '' ? () : $name); 1 }
Branch: 2 branches
BranchTrueFalseTotal
eval { do { "Text::ANSI::Highlight::IO"->setup($name eq "" ? () : $name); 1 } } or die $@ =~ s/ at .* line \d+\.?\n\z/\n/ru 19 1 20
$name eq '' ? : 12 8 20
281 or die $@ =~ s/ at .* line \d+\.?\n\z/\n/r;
282 }
283  
284 248 ▶ warn Dumper $obj if $obj->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->debug 0 248 248
285  
286 248 ▶ my @files = $obj->read_files(@ARGV ? @ARGV : '-') or return 1;
Branch: 2 branches
BranchTrueFalseTotal
my(@files) = $obj->read_files(@ARGV ? @ARGV : "-") or return 1 246 0 246
@ARGV ? : 43 205 248
287  
288 246 ▶ if ($obj->ignore_empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->ignore_empty) 0 246 246
289 0 @files = grep { not $_->is_empty } @files;
290 }
291  
292 246 ▶ if ($obj->table) {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->table) { } 138 108 246
elsif ($obj->parallel) { } 18 90 108
293 138 my @lines = map { $_->lines } @files;
294 138 $obj->table_out(@lines);
295 }
296 elsif ($obj->parallel) {
297 18 $obj->parallel_out(@files);
298 }
299 else {
300 90 $obj->nup_out(@files);
301 }
302  
303 246 return 0
304 }
305  
306 251 ▶sub setup_options {
Subroutine setup_options: called CC=30 SCAR=38.6
Pod undocumented
307 251 my $obj = shift;
308  
309 ## --parallel or @ARGV > 1
310 251 ▶ if ($obj->parallel //= @ARGV > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->parallel //= @ARGV > 1) 18 233 251
Condition100%2/2
$obj->parallel //= @ARGV > 1
l!l
17234
MC/DC100%1/1
$obj->parallel //= @ARGV > 1
$obj->parallel
Truth table100%2/2
A
A= $obj->parallel
Aresult
11
00
311 18 ▶ $obj->linestyle ||= 'wrap';
Condition50%1/2
$obj->linestyle ||= "wrap"
l!l
018
MC/DC0%0/1
$obj->linestyle ||= "wrap"
$obj->linestyle
Truth table50%1/2
A
A= $obj->linestyle
Aresult
11
00
312 18 ▶ $obj->widen //= 1;
Condition50%1/2
$obj->widen //= 1
l!l
018
MC/DC0%0/1
$obj->widen //= 1
$obj->widen
Truth table50%1/2
A
A= $obj->widen
Aresult
11
00
313 18 ▶ $obj->border //= '';
Condition100%2/2
$obj->border //= ""
l!l
135
MC/DC100%1/1
$obj->border //= ""
$obj->border
Truth table100%2/2
A
A= $obj->border
Aresult
11
00
314 }
315  
316 ## --border takes optional border-style value
317 251 ▶ if (defined(my $border = $obj->border)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $border = $obj->border)) 46 205 251
318 46 ▶ if ($border ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($border ne "") 21 25 46
319 21 $obj->border_style = $border;
320 }
321 46 $obj->border = 1;
322 46 ▶ $obj->fillup //= 'pane';
Condition100%2/2
$obj->fillup //= "pane"
l!l
343
MC/DC100%1/1
$obj->fillup //= "pane"
$obj->fillup
Truth table100%2/2
A
A= $obj->fillup
Aresult
11
00
323 }
324  
325 ## --linestyle
326 251 ▶ if ($obj->linestyle eq 'wordwrap') {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->linestyle eq "wordwrap") 0 251 251
327 0 $obj->linestyle = 'wrap';
328 0 $obj->boundary = 'word';
329 }
330  
331 ## -P
332 251 ▶ if (defined $obj->page) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->page) 34 217 251
333 34 ▶ $obj->widen = 1 if $obj->pane and not $obj->pane_width;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->pane and not $obj->pane_width 26 8 34
Condition66%2/3
$obj->pane and not $obj->pane_width
!ll&&!rl&&r
8026
MC/DC50%1/2
$obj->pane and not $obj->pane_width
$obj->pane not $obj->pane_width
Truth table66%2/3
A and not(B)
A= $obj->paneB= not $obj->pane_width
ABresult
0X0
100
111
334 34 ▶ $obj->height ||= $obj->page || $obj->term_height - 1;
Condition33%2/6
$obj->height ||= $obj->page || $obj->term_height - 1
l!l&&r!l&&!r
0340
$obj->page || $obj->term_height - 1
l!l&&r!l&&!r
3400
MC/DC0%0/3
$obj->height ||= $obj->page || $obj->term_height - 1
$obj->height $obj->page $obj->term_height - 1
Truth table0%0/4
A ||= B || C
A= $obj->heightB= $obj->pageC= $obj->term_height - 1
ABCresult
1XX1
01X1
0011
0000
335 34 ▶ $obj->linestyle ||= 'wrap';
Condition50%1/2
$obj->linestyle ||= "wrap"
l!l
034
MC/DC0%0/1
$obj->linestyle ||= "wrap"
$obj->linestyle
Truth table50%1/2
A
A= $obj->linestyle
Aresult
11
00
336 34 ▶ $obj->border //= 1;
Condition100%2/2
$obj->border //= 1
l!l
286
MC/DC100%1/1
$obj->border //= 1
$obj->border
Truth table100%2/2
A
A= $obj->border
Aresult
11
00
337 34 ▶ $obj->fillup //= 'pane';
Condition100%2/2
$obj->fillup //= "pane"
l!l
286
MC/DC100%1/1
$obj->fillup //= "pane"
$obj->fillup
Truth table100%2/2
A
A= $obj->fillup
Aresult
11
00
338 }
339  
340 ## -U
341 251 ▶ if ($obj->up) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->up) 0 251 251
342 0 $obj->pane = $obj->up;
343 0 $obj->widen = 1;
344 0 ▶ $obj->linestyle ||= 'wrap';
Condition0%0/2
$obj->linestyle ||= "wrap"
l!l
00
MC/DC0%0/1
$obj->linestyle ||= "wrap"
$obj->linestyle
Truth table0%0/2
A
A= $obj->linestyle
Aresult
11
00
345 0 ▶ $obj->border //= 1;
Condition0%0/2
$obj->border //= 1
l!l
00
MC/DC0%0/1
$obj->border //= 1
$obj->border
Truth table0%0/2
A
A= $obj->border
Aresult
11
00
346 0 ▶ $obj->fillup //= 'pane';
Condition0%0/2
$obj->fillup //= "pane"
l!l
00
MC/DC0%0/1
$obj->fillup //= "pane"
$obj->fillup
Truth table0%0/2
A
A= $obj->fillup
Aresult
11
00
347 }
348  
349 ## -D
350 251 ▶ if ($obj->document) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->document) 20 231 251
351 20 $obj->widen = 1;
352 20 ▶ $obj->linebreak ||= 'all';
Condition50%1/2
$obj->linebreak ||= "all"
l!l
020
MC/DC0%0/1
$obj->linebreak ||= "all"
$obj->linebreak
Truth table50%1/2
A
A= $obj->linebreak
Aresult
11
00
353 20 ▶ $obj->linestyle ||= 'wrap';
Condition100%2/2
$obj->linestyle ||= "wrap"
l!l
515
MC/DC100%1/1
$obj->linestyle ||= "wrap"
$obj->linestyle
Truth table100%2/2
A
A= $obj->linestyle
Aresult
11
00
354 20 ▶ $obj->boundary ||= 'word';
Condition50%1/2
$obj->boundary ||= "word"
l!l
020
MC/DC0%0/1
$obj->boundary ||= "word"
$obj->boundary
Truth table50%1/2
A
A= $obj->boundary
Aresult
11
00
355 20 ▶ $obj->white_space = 0 if $obj->white_space > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->white_space > 1 20 0 20
356 20 ▶ $obj->isolation = 0 if $obj->isolation > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->isolation > 1 20 0 20
357 }
358  
359 ## --colormap
360 253 ▶ use Getopt::EX::Colormap;
Subroutine BEGIN: called CC=1 SCAR=0.0
361 my $cm = Getopt::EX::Colormap
362 ->new(HASH => $obj->{COLORHASH}, LIST => $obj->{COLORLIST})
363 251 ->load_params(@{$obj->colormap});
364 251 ▶ $obj->{COLOR} = sub { $cm->color(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
365  
366 ## --border
367 251 ▶ if ($obj->border) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->border) 52 199 251
368 52 my $style = $obj->border_style;
369 52 ▶ ($obj->{BORDER} = App::ansicolumn::Border->new)
Condition50%1/2
($obj->{"BORDER"} = "App::ansicolumn::Border"->new)->style($style) // die("${style}: Unknown style.\n")
l!l
520
MC/DC0%0/1
($obj->{"BORDER"} = "App::ansicolumn::Border"->new)->style($style) // die("${style}: Unknown style.\n")
($obj->{"BORDER"} = "App::ansicolumn::Border"->new)->style($style)
Truth table50%1/2
A
A= ($obj->{"BORDER"} = "App::ansicolumn::Border"->new)->style($style)
Aresult
11
00
370 ->style($style) // die "$style: Unknown style.\n";
371 }
372  
373 251 $obj;
374 }
375  
376 2926 ▶sub color {
Subroutine color: called CC=1 SCAR=0.0
Pod undocumented
377 2926 my $obj = shift;
378 2926 $obj->{COLOR}->(@_);
379 }
380  
381 18 ▶sub parallel_out {
Subroutine parallel_out: called CC=14 SCAR=28.3
Pod undocumented
382 18 my $obj = shift;
383 18 my @files = @_;
384  
385 18 my $max_line_length = max map { $_->width } @files;
386 18 ▶ $obj->pane ||= @files;
Condition66%2/3
$obj->pane ||= @files
l!l&&r!l&&!r
8100
MC/DC0%0/2
$obj->pane ||= @files
$obj->pane @files
Truth table66%2/3
A ||= B
A= $obj->paneB= @files
ABresult
1X1
011
000
387 18 $obj->set_horizontal($max_line_length);
388  
389 # calculate span and set for each file
390 18 ▶ if (my $cell = $obj->cell) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cell = $obj->cell) 1 17 18
391 1 my @spans = split /,+/, $cell;
392 1 for my $i (keys @files) {
393 2 ▶ my $span = $spans[$i] // $spans[-1];
Condition33%1/3
$spans[$i] // $spans[-1]
l!l&&r!l&&!r
200
MC/DC0%0/2
$spans[$i] // $spans[-1]
$spans[$i] $spans[-1]
Truth table33%1/3
A // B
A= $spans[$i]B= $spans[-1]
ABresult
1X1
011
000
394 2 ▶ if ($span =~ /^[-+]/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($span =~ /^[-+]/u) { } 0 2 2
elsif ($span =~ s/^(<=|[<=])//u) { } 0 2 2
elsif (not $span =~ /^\d+$/u) { } 0 2 2
395 0 $span += $obj->{span};
396 0 ▶ $span < 0 and die "Invalid number: $cell\n";
Branch: 1 branch
BranchTrueFalseTotal
$span < 0 and die "Invalid number: $cell\n" 0 0 0
397 }
398 elsif ($span =~ s/^(<=|[<=])//) {
399 0 my $length = $files[$i]->width;
400 0 ▶ $span = $span ? min($length, $span) : $length;
Branch: 1 branch
BranchTrueFalseTotal
$span ? : 0 0 0
401 }
402 elsif ($span !~ /^\d+$/) {
403 0 die "Invalid number: $cell\n";
404 }
405 2 $files[$i]->span($span);
406 }
407 }
408 18 $obj->set_contents($_) for @files;
409 # for the labels: every file is a pane
410 18 $obj->{_total_panes} = @files;
411 18 $obj->{_total_pages} = roundup(scalar @files, $obj->pane) / $obj->pane;
412 18 my $column_out = $obj->_column_out;
413 18 ▶ for ($obj->current_page = 0; @files; $obj->current_page++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) 19 18 37
414 19 my @rows = splice @files, 0, $obj->pane;
415 19 my @data = map { [ $_->lines ] } @rows;
416 19 my $max_length = max map { int @$_ } @data;
417 19 ▶ my @span = map { $_->span // $obj->span } @rows;
Condition66%2/3
$_->span // $obj->span
l!l&&r!l&&!r
2360
MC/DC0%0/2
$_->span // $obj->span
$_->span $obj->span
Truth table66%2/3
A // B
A= $_->spanB= $obj->span
ABresult
1X1
011
000
418 19 ▶ if ($obj->filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->filename) 3 16 19
419 3 my $w = $obj->span + $obj->border_width('center');
420 my $format = join '', (
421 (map {
422 3 my $w = $_ + $obj->border_width('center');
423 3 "%-${w}.${w}s";
424 } @span[0..$#span-1]),
425 "%s\n");
426 ansi_printf $format, map {
427 3 ansi_sprintf $obj->filename_format, $_->name;
428 } @rows;
429 }
430 $column_out->({ span => \@span, names => [ map $_->name, @rows ] },
431 map {
432 19 push @$_, (($obj->fillup_str) x ($max_length - @$_));
433 38 $_;
434 } @data);
435 }
436 18 return $obj;
437 }
438  
439 90 ▶sub nup_out {
Subroutine nup_out: called CC=3 SCAR=11.0
Pod undocumented
440 90 my $obj = shift;
441 90 my @files = @_;
442 90 my $max_length = max map { $_->width } @files;
443 90 $obj->set_horizontal($max_length);
444 90 for my $file (@files) {
445 91 ▶ next if $file->is_empty;
Branch: 1 branch
BranchTrueFalseTotal
if $file->is_empty 3 88 91
446 88 my $page = clone($obj)->set_contents($file);
447 88 my @data;
448 88 $page->set_vertical([ $file->lines ])
449 ->set_layout(\@data, $file->parts);
450 88 $page->page_out($file->name, @data);
451 }
452 90 return $obj;
453 }
454  
455 248 ▶sub read_files {
Subroutine read_files: called CC=11 SCAR=24.5
Pod undocumented
456 248 my $obj = shift;
457 # The content is divided at formfeeds where a formfeed is a break.
458 # It is not with --no-pagebreak, and in the table and the parallel
459 # view, where the panes are not filled: the formfeeds are left in
460 # the text there. --pages divides it in any case, and makes a
461 # file of every part.
462 248 ▶ my $divide = $obj->pages ||
Condition100%9/9
$obj->pages || $obj->pagebreak && !$obj->parallel && !$obj->table
l!l&&r!l&&!r
990149
$obj->pagebreak and not $obj->parallel and not $obj->table
!ll&&!rl&&r
1113890
$obj->pagebreak and not $obj->parallel
!ll&&!rl&&r
110228
MC/DC100%4/4
$obj->pages || $obj->pagebreak && !$obj->parallel && !$obj->table
$obj->pages $obj->pagebreak not $obj->parallel not $obj->table
Truth table100%5/5
A || B and not(C) and not(D)
A= $obj->pagesB= $obj->pagebreakC= not $obj->parallelD= not $obj->table
ABCDresult
1XXX1
01111
00XX0
010X0
01100
463 ($obj->pagebreak && !$obj->parallel && !$obj->table);
464 248 my @files;
465 # When IO::Factotum is loaded (--factotum=NAME), the files
466 # are opened by it, and those which a converter takes are read
467 # through that converter. The names stay as they are.
468 248 my $factotum = IO::Factotum->can('open_input');
469 248 for my $file (@_) {
470 258 my $fh;
471 258 ▶ if ($factotum) {
Branch: 1 branch
BranchTrueFalseTotal
if ($factotum) { } 34 224 258
472 34 ▶ $fh = $factotum->($file) or die "$file: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh = &$factotum($file) or die "${file}: $!" 32 2 34
473 32 binmode $fh, ':utf8';
474 } else {
475 224 ▶ open $fh, $file or die "$file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $file or die "${file}: $!" 224 0 224
476 }
477 256 ▶ my $content = do { local $/; <$fh> } // do {
Condition33%1/3
do { local $/; readline $fh } // do { warn "${file}: $!\n" if $!; next }
l!l&&r!l&&!r
25600
MC/DC0%0/2
do { local $/; readline $fh } // do { warn "${file}: $!\n" if $!; next }
do { local $/; readline $fh } do { warn "${file}: $!\n" if $!; next }
Truth table33%1/3
A // B
A= do { local $/; readline $fh }B= do { warn "${file}: $!\n" if $!; next }
ABresult
1X1
011
000
478 0 ▶ warn "$file: $!\n" if $!;
Branch: 1 branch
BranchTrueFalseTotal
if $! 0 0 0
479 0 next;
480 };
481 256 my $doc = App::ansicolumn::Document->new(
482 name => $file,
483 text => $content,
484 formfeed => $divide,
485 keep_ls => $obj->table,
486 );
487 256 ▶ push @files, map { $obj->prepare($_) }
Branch: 1 branch
BranchTrueFalseTotal
$obj->pages ? : 9 247 256
488 $obj->pages ? $doc->pages : $doc;
489 }
490 246 @files;
491 }
492  
493 #
494 # Make the lines of a document ready to be laid out, and find the
495 # width of the longest.
496 #
497 267 ▶sub prepare {
Subroutine prepare: called CC=6 SCAR=17.9
Pod undocumented
498 267 my $obj = shift;
499 267 my $doc = shift;
500 267 ▶ my $intact = $obj->intact && !$obj->table;
Condition100%3/3
$obj->intact && !$obj->table
!ll&&!rl&&r
26115
MC/DC100%2/2
$obj->intact && !$obj->table
$obj->intact !$obj->table
Truth table100%3/3
A && not(B)
A= $obj->intactB= !$obj->table
ABresult
0X0
100
111
501 # --intact: a line which has the separator holds lines to be kept
502 # intact, joined into one; it is divided into them, and every one
503 # keeps the separator at its start as its mark, until the line is
504 # folded (set_contents)
505 5 ▶ $doc->filter(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
506 5 ▶ map { /$INTACT_SEP/ ? map("$INTACT_SEP$_", split /$INTACT_SEP/, $_, -1) : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
/$App::ansicolumn::INTACT_SEP/u ? : 5 4 9
507 267 ▶ }) if $intact;
Branch: 1 branch
BranchTrueFalseTotal
if $intact 5 262 267
508 267 ▶ $doc->filter(\&insert_space) if $obj->paragraph;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->paragraph 0 267 267
509 267 my @width;
510 267 ▶ if ($obj->table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->table) { } 138 129 267
511 138 @width = map { length } $doc->lines;
512 } else {
513 1156 ▶ $doc->replace(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
514 1156 my $line = shift;
515 1156 ▶ my $mark = $intact && $line =~ s/^$INTACT_SEP//;
Condition100%3/3
$intact && $line =~ s/^$App::ansicolumn::INTACT_SEP//u
!ll&&!rl&&r
1141411
MC/DC100%2/2
$intact && $line =~ s/^$App::ansicolumn::INTACT_SEP//u
$intact $line =~ s/^$App::ansicolumn::INTACT_SEP//u
Truth table100%3/3
A && B
A= $intactB= $line =~ s/^$App::ansicolumn::INTACT_SEP//u
ABresult
0X0
100
111
516 1156 my($text, $width) = $obj->expand_tab($line);
517 1156 push @width, $width;
518 1156 ▶ $mark ? "$INTACT_SEP$text" : $text;
Branch: 1 branch
BranchTrueFalseTotal
$mark ? : 11 1145 1156
519 129 });
520 }
521 267 ▶ $doc->width(max(@width) // 0);
Condition100%2/2
&max(@width) // 0
l!l
2616
MC/DC100%1/1
&max(@width) // 0
&max(@width)
Truth table100%2/2
A
A= &max(@width)
Aresult
11
00
522 267 $doc;
523 }
524  
525 #
526 # Expand the tabs in a line. Returns the line and its width.
527 #
528 1156 ▶sub expand_tab {
Subroutine expand_tab: called CC=6 SCAR=18.0
Pod undocumented
529 1156 my $obj = shift;
530 1156 my $text = shift;
531 1156 my($result, $width) = ('', 0);
532 1156 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$text ne "" and do { do { () = ansi_fold($text, -1, "expand", 1); $result .= $folded; $width = $w if $w > $width; $result .= $1 if $rest =~ s/^(\f+)//u; $rest eq "" or $rest ne $text or die sprintf("Text is not consumed, at %s (please report this).\n", $rest =~ s/([^\x20-\x7e])/sprintf "\x{%02x}", ord $1;/egru); $text = $rest } } 2 1156 1158
533 1158 my($folded, $rest, $w) = ansi_fold $text, -1, expand => 1;
534 1158 $result .= $folded;
535 1158 ▶ $width = $w if $w > $width;
Branch: 1 branch
BranchTrueFalseTotal
if $w > $width 1061 97 1158
536 # ansi_fold stops before formfeeds in the middle of the text
537 1158 ▶ $result .= $1 if $rest =~ s/^(\f+)//;
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ s/^(\f+)//u 2 1156 1158
538 # every turn must take something from the text; otherwise
539 # this loop never ends
540 1158 ▶ $rest eq '' or $rest ne $text or die sprintf
Branch: 1 branch
BranchTrueFalseTotal
$rest eq "" or $rest ne $text or die sprintf("Text is not consumed, at %s (please report this).\n", $rest =~ s/([^\x20-\x7e])/sprintf "\x{%02x}", ord $1;/egru) 1158 0 1158
Condition66%2/3
$rest eq "" or $rest ne $text
l!l&&r!l&&!r
115620
MC/DC0%0/2
$rest eq "" or $rest ne $text
$rest eq "" $rest ne $text
Truth table66%2/3
A or B
A= $rest eq ""B= $rest ne $text
ABresult
1X1
011
000
541 "Text is not consumed, at %s (please report this).\n",
542 0 $rest =~ s/([^\x20-\x7e])/sprintf '\\x{%02x}', ord $1/ger;
543 1158 $text = $rest;
544 } while ($text ne '');
545 1156 ($result, $width);
546 }
547  
548 108 ▶sub set_horizontal {
Subroutine set_horizontal: called CC=11 SCAR=24.3
Pod undocumented
549 108 my $obj = shift;
550 108 my $max_data_length = shift;
551  
552 253 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
553 108 my $width = $obj->get_width - $obj->border_width(qw(left right));
554 108 ▶ my $unit = $obj->column_unit // 1;
Condition50%1/2
$obj->column_unit // 1
l!l
1080
MC/DC0%0/1
$obj->column_unit // 1
$obj->column_unit
Truth table50%1/2
A
A= $obj->column_unit
Aresult
11
00
555  
556 108 my $span;
557 my $panes;
558 108 ▶ my $claim = sum($max_data_length,
Condition66%2/3
$obj->border_width('center') || $obj->margin
l!l&&r!l&&!r
30780
MC/DC0%0/2
$obj->border_width('center') || $obj->margin
$obj->border_width('center') $obj->margin
Truth table66%2/3
A || B
A= $obj->border_width('center')B= $obj->margin
ABresult
1X1
011
000
559 $obj->runin_margin,
560 $obj->border_width('center') || $obj->margin);
561 108 ▶ if ($obj->widen and not $obj->pane_width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->widen and not $obj->pane_width) { } 59 49 108
Condition66%2/3
$obj->widen and not $obj->pane_width
!ll&&!rl&&r
49059
MC/DC50%1/2
$obj->widen and not $obj->pane_width
$obj->widen not $obj->pane_width
Truth table66%2/3
A and not(B)
A= $obj->widenB= not $obj->pane_width
ABresult
0X0
100
111
562 59 ▶ $panes = $obj->pane || $width / $claim || 1;
Condition80%4/5
$obj->pane || $width / $claim || 1
l!l
581
$obj->pane or $width / $claim
l!l&&r!l&&!r
5801
MC/DC50%1/2
$obj->pane || $width / $claim || 1
$obj->pane $width / $claim
Truth table66%2/3
A or B
A= $obj->paneB= $width / $claim
ABresult
1X1
011
000
563 59 $span = ($width + $obj->border_width('center')) / $panes;
564 } else {
565 49 ▶ $span = $obj->pane_width || roundup($claim, $unit);
Condition66%2/3
$obj->pane_width || &roundup($claim, $unit)
l!l&&r!l&&!r
5440
MC/DC0%0/2
$obj->pane_width || &roundup($claim, $unit)
$obj->pane_width &roundup($claim, $unit)
Truth table66%2/3
A || B
A= $obj->pane_widthB= &roundup($claim, $unit)
ABresult
1X1
011
000
566 49 ▶ $panes = $obj->pane || $width / $span || 1;
Condition100%5/5
$obj->pane || $width / $span || 1
l!l
481
$obj->pane or $width / $span
l!l&&r!l&&!r
37111
MC/DC100%2/2
$obj->pane || $width / $span || 1
$obj->pane $width / $span
Truth table100%3/3
A or B
A= $obj->paneB= $width / $span
ABresult
1X1
011
000
567 }
568 108 $span -= $obj->border_width('center');
569 108 ▶ $span < 1 and die "Not enough space.\n";
Branch: 1 branch
BranchTrueFalseTotal
$span < 1 and die "Not enough space. " 0 108 108
570  
571 108 ($obj->span, $obj->panes) = ($span, $panes);
572  
573 108 return $obj;
574 }
575  
576 126 ▶sub set_contents {
Subroutine set_contents: called CC=9 SCAR=22.1
Pod undocumented
577 126 my $obj = shift;
578 126 my $fp = shift;
579 126 ▶ (my $cell_width = $obj->span) < 1
Branch: 1 branch
BranchTrueFalseTotal
(my $cell_width = $obj->span) < 1 and die "Not enough space. " 0 126 126
580 and die "Not enough space.\n";
581 # Fold long lines
582 126 ▶ my $intact = $obj->intact && !$obj->table;
Condition66%2/3
$obj->intact && !$obj->table
!ll&&!rl&&r
12105
MC/DC50%1/2
$obj->intact && !$obj->table
$obj->intact !$obj->table
Truth table66%2/3
A && not(B)
A= $obj->intactB= !$obj->table
ABresult
0X0
100
111
583 126 ▶ if ($obj->linestyle and $obj->linestyle ne 'none') {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->linestyle and $obj->linestyle ne 'none') { } 88 38 126
elsif ($intact) { } 2 36 38
Condition66%2/3
$obj->linestyle and $obj->linestyle ne "none"
!ll&&!rl&&r
38088
MC/DC50%1/2
$obj->linestyle and $obj->linestyle ne "none"
$obj->linestyle $obj->linestyle ne "none"
Truth table66%2/3
A and B
A= $obj->linestyleB= $obj->linestyle ne "none"
ABresult
0X0
100
111
584 88 ▶ my $w = $fp->span // $cell_width;
Condition66%2/3
$fp->span // $cell_width
l!l&&r!l&&!r
2860
MC/DC0%0/2
$fp->span // $cell_width
$fp->span $cell_width
Truth table66%2/3
A // B
A= $fp->spanB= $cell_width
ABresult
1X1
011
000
585 88 ▶ my $fold = $obj->foldsub($w) or die;
Branch: 1 branch
BranchTrueFalseTotal
my $fold = $obj->foldsub($w) or die 88 0 88
586 88 ▶ if ($intact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($intact) 3 85 88
587 # A line kept intact is laid out as it is: the room kept for
588 # run-in characters, word boundaries and line-break (kinsoku)
589 # rules are for text folded into lines. One that fits the
590 # pane is not folded, and a wider one is cut at the pane
591 # width, as a terminal does with a long line.
592 3 my $intact_fold = $obj->foldobj($w);
593 3 $intact_fold->configure(
594 margin => 0,
595 boundary => '',
596 linebreak => Text::ANSI::Fold::LINEBREAK_NONE,
597 );
598 3 my $line_fold = $fold;
599 3 my $truncate = $obj->linestyle eq 'truncate';
600 10 ▶ $fold = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
601 10 my $line = shift;
602 10 ▶ $line =~ s/^$INTACT_SEP// or return $line_fold->($line);
Branch: 1 branch
BranchTrueFalseTotal
$line =~ s/^$App::ansicolumn::INTACT_SEP//u or return &$line_fold($line) 7 3 10
603 7 my @chops = $intact_fold->text($line)->chops;
604 7 ▶ $truncate ? $chops[0] : @chops;
Branch: 1 branch
BranchTrueFalseTotal
$truncate ? : 2 5 7
605 3 };
606 }
607 88 $fp->replace($fold);
608 }
609 elsif ($intact) {
610 2 ▶ $fp->replace(sub { $_[0] =~ s/^$INTACT_SEP//r });
Subroutine __ANON__: called CC=1 SCAR=0.0
611 }
612 126 return $obj;
613 }
614  
615 88 ▶sub set_vertical {
Subroutine set_vertical: called CC=3 SCAR=11.1
Pod undocumented
616 88 my $obj = shift;
617 88 my $dp = shift;
618 88 $obj->border_height = do {
619 176 sum map { length > 0 }
620 88 map { $obj->get_border($_) }
621 qw(top bottom);
622 };
623 88 ▶ $obj->height ||= div(int @$dp, $obj->panes) + $obj->border_height;
Condition66%2/3
$obj->height ||= div(int @$dp, $obj->panes) + $obj->border_height
l!l&&r!l&&!r
52360
MC/DC0%0/2
$obj->height ||= div(int @$dp, $obj->panes) + $obj->border_height
$obj->height div(int @$dp, $obj->panes) + $obj->border_height
Truth table66%2/3
A ||= B
A= $obj->heightB= div(int @$dp, $obj->panes) + $obj->border_height
ABresult
1X1
011
000
624 88 ▶ die "Not enough height.\n" if $obj->effective_height <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->effective_height <= 0 0 88 88
625 88 return $obj;
626 }
627  
628 88 ▶sub page_out {
Subroutine page_out: called CC=6 SCAR=17.9
Pod undocumented
629 88 my $obj = shift;
630 88 my $name = shift;
631 # for the labels: the numbers of all the pages and the panes. A
632 # page is filled by panes, or by rows with --fillrows; the last
633 # one has the panes which the rest of the lines take.
634 {
635 88 my($lines, $panes, $height) = (scalar @_, $obj->panes, $obj->effective_height);
636 88 my $pages = roundup($lines, $panes * $height) / ($panes * $height);
637 88 my $rest = $lines - ($pages - 1) * $panes * $height;
638 88 ▶ my $last = $pages == 0 ? 0
Branch: 2 branches
BranchTrueFalseTotal
$pages == 0 ? : 0 88 88
$obj->fillrows ? : 1 87 88
639 : $obj->fillrows ? min($panes, $rest)
640 : roundup($rest, $height) / $height;
641 88 $obj->{_total_pages} = $pages;
642 88 ▶ $obj->{_total_panes} = $pages == 0 ? 0 : ($pages - 1) * $panes + $last;
Branch: 1 branch
BranchTrueFalseTotal
$pages == 0 ? : 0 88 88
643 }
644 88 my $column_out = $obj->_column_out;
645 88 ▶ for ($obj->current_page = 0; @_; $obj->current_page++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 227 88 315
646 227 my @columns = grep { @$_ } do {
647 227 ▶ if ($obj->fillrows) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->fillrows) { } 1 226 227
648 1 xpose map { [ splice @_, 0, $obj->panes ] } 1 .. $obj->effective_height;
649 } else {
650 226 map { [ splice @_, 0, $obj->effective_height ] } 1 .. $obj->panes;
651 }
652 };
653 227 $column_out->({ names => [($name) x scalar @columns] }, @columns);
654 }
655 88 return $obj;
656 }
657  
658 954 ▶sub color_border {
Subroutine color_border: called CC=1 SCAR=0.0
Pod undocumented
659 954 my $obj = shift;
660 954 $obj->color('BORDER', $obj->get_border(@_));
661 }
662  
663 212 ▶sub _parse_labels {
Subroutine _parse_labels: called CC=7 SCAR=19.8
664 212 my $hash = shift;
665 212 ▶ return 0 unless %$hash;
Branch: 1 branch
BranchTrueFalseTotal
unless %$hash 193 19 212
666 19 my %result;
667 19 ▶ while (my($key, $s) = each %$hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 26 19 45
668 26 ▶ next unless defined $s and $s ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and $s ne "" 0 26 26
Condition33%1/3
defined $s and $s ne ""
!ll&&!rl&&r
0026
MC/DC0%0/2
defined $s and $s ne ""
defined $s $s ne ""
Truth table33%1/3
A and B
A= defined $sB= $s ne ""
ABresult
0X0
100
111
669 26 my $offset;
670 26 ▶ if ($s =~ s/@(\d+)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ s/@(\d+)$//u) 0 26 26
671 0 $offset = $1 + 0;
672 }
673 # the marks are empty where there is nothing in that direction,
674 # and a label left with no text by them is not shown
675 26 my $marked = $s =~ /%[LRUD]/;
676 26 $s =~ s/%n/%1\$d/g;
677 26 $s =~ s/%p/%2\$d/g;
678 26 $s =~ s/%f/%3\$s/g;
679 26 $s =~ s/%F/%4\$s/g;
680 26 $s =~ s/%N/%5\$d/g;
681 26 $s =~ s/%P/%6\$d/g;
682 26 $s =~ s/%L/%7\$s/g;
683 26 $s =~ s/%R/%8\$s/g;
684 26 $s =~ s/%U/%9\$s/g;
685 26 $s =~ s/%D/%10\$s/g;
686 26 $result{lc $key} = [ $offset, $s, $marked ];
687 }
688 19 ▶ %result ? \%result : 0;
Branch: 1 branch
BranchTrueFalseTotal
%result ? : 19 0 19
689 }
690  
691 # The marks of --label for the directions with something there, set
692 # by --mark
693 253 my %MARK = (
694 LEFT => '<', RIGHT => '>', UP => '^', DOWN => 'v',
695 # where there is nothing in that direction
696 LEFT_END => '', RIGHT_END => '', UP_END => '', DOWN_END => '',
697 );
698  
699 420 ▶sub _marks {
Subroutine _marks: called CC=4 SCAR=13.9
700 420 my $obj = shift;
701 420 ▶ $obj->{_mk} //= do {
Condition100%3/3
$obj->{"_mk"} //= do { my(%mark) = %MARK; while (() = each %{$obj->mark;}) { do { exists $mark{uc $name} or die "${name}: unknown mark\n"; $mark{uc $name} = $text }; } ; \%mark }
l!l&&r!l&&!r
1692501
MC/DC100%2/2
$obj->{"_mk"} //= do { my(%mark) = %MARK; while (() = each %{$obj->mark;}) { do { exists $mark{uc $name} or die "${name}: unknown mark\n"; $mark{uc $name} = $text }; } ; \%mark }
$obj->{"_mk"} do { my(%mark) = %MARK; while (() = each %{$obj->mark;}) { do { exists $mark{uc $name} or die "${name}: unknown mark\n"; $mark{uc $name} = $text }; } ; \%mark }
Truth table100%3/3
A //= B
A= $obj->{"_mk"}B= do { my(%mark) = %MARK; while (() = each %{$obj->mark;}) { do { exists $mark{uc $name} or die "${name}: unknown mark\n"; $mark{uc $name} = $text }; } ; \%mark }
ABresult
1X1
011
000
702 251 my %mark = %MARK;
703 251 ▶ while (my($name, $text) = each %{$obj->mark}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$obj->mark;}) 21 250 271
704 21 ▶ exists $mark{uc $name} or die "$name: unknown mark\n";
Branch: 1 branch
BranchTrueFalseTotal
exists $mark{uc $name} or die "${name}: unknown mark\n" 20 1 21
705 20 $mark{uc $name} = $text;
706 }
707 250 \%mark;
708 };
709 }
710  
711 # What a label has besides the numbers of the pane and the page: the
712 # numbers of all the panes and pages, and the marks. $p is the page
713 # (from 1), $i the pane in the row (from 0) of $npanes panes; a label
714 # of the page has no pane, and no mark for the left and the right.
715 169 ▶sub _label_more {
Subroutine _label_more: called CC=9 SCAR=22.1
716 169 my($obj, $p, $i, $npanes) = @_;
717 169 my $mark = $obj->_marks;
718 169 ▶ my $pages = $obj->{_total_pages} // 0;
Condition50%1/2
$obj->{"_total_pages"} // 0
l!l
1690
MC/DC0%0/1
$obj->{"_total_pages"} // 0
$obj->{"_total_pages"}
Truth table50%1/2
A
A= $obj->{"_total_pages"}
Aresult
11
00
719 [ $obj->{_total_panes} // 0, $pages,
720 (!defined $i ? '' : $i > 0 ? $mark->{LEFT} : $mark->{LEFT_END}),
721 (!defined $i ? '' : $i < $npanes - 1 ? $mark->{RIGHT} : $mark->{RIGHT_END}),
722 ($p > 1 ? $mark->{UP} : $mark->{UP_END}),
723 169 ▶ ($p < $pages ? $mark->{DOWN} : $mark->{DOWN_END}) ];
Branch: 6 branches
BranchTrueFalseTotal
!defined($i) ? : 16 153 169
$i > 0 ? : 19 134 153
!defined($i) ? : 16 153 169
$i < $npanes - 1 ? : 19 134 153
$p > 1 ? : 134 35 169
$p < $pages ? : 147 22 169
Condition50%1/2
$obj->{"_total_panes"} // 0
l!l
1690
MC/DC0%0/1
$obj->{"_total_panes"} // 0
$obj->{"_total_panes"}
Truth table50%1/2
A
A= $obj->{"_total_panes"}
Aresult
11
00
724 }
725  
726 # Overlay labels onto a border line string.
727 # $fs/$fe: fill region start/end.
728 # $ml/$mr: border margin accessible via @0.
729 # $n/$p: pane number / page number for sprintf expansion.
730 # $file: filename (path as given) - used as %3$s (basename) and %4$s (path as given).
731 # $more: the numbers of all the panes and pages (%N, %P), and the
732 # marks for the left, right, up and down (%L, %R, %U, %D), each empty
733 # where there is nothing in that direction.
734 169 ▶sub _overlay_labels {
Subroutine _overlay_labels: called CC=15 SCAR=27.7
735 169 my($obj, $str, $fs, $fe, $ml, $mr, $n, $p, $file, $more, $left, $center, $right) = @_;
736 253 ▶ use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
737 253 ▶ use Text::ANSI::Fold::Util qw(ansi_substr);
Subroutine BEGIN: called CC=1 SCAR=0.0
738 169 ▶ my $base = defined $file ? basename($file) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 169 0 169
739 169 for my $item (
740 5 ▶ [ $left, sub { $fs - $ml + ($_[0] // $ml) } ],
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
$_[0] // $ml
l!l&&r!l&&!r
050
MC/DC0%0/2
$_[0] // $ml
$_[0] $ml
Truth table33%1/3
A // B
A= $_[0]B= $ml
ABresult
1X1
011
000
741 8 ▶ [ $right, sub { $fe + $mr - ($_[0] // $mr) - $_[1] } ],
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
$_[0] // $mr
l!l&&r!l&&!r
080
MC/DC0%0/2
$_[0] // $mr
$_[0] $mr
Truth table33%1/3
A // B
A= $_[0]B= $mr
ABresult
1X1
011
000
742 240 ▶ [ $center, sub { $fs + int(($fe - $fs - $_[1]) / 2) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
743 ) {
744 507 my($spec, $pos_fn) = @$item;
745 507 ▶ next unless $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless $spec 327 180 507
746 180 my $fmt = $spec->[1];
747 180 ▶ next unless defined $fmt && $fmt ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt and $fmt ne "" 0 180 180
Condition33%1/3
defined $fmt and $fmt ne ""
!ll&&!rl&&r
00180
MC/DC0%0/2
defined $fmt and $fmt ne ""
defined $fmt $fmt ne ""
Truth table33%1/3
A and B
A= defined $fmtB= $fmt ne ""
ABresult
0X0
100
111
748 180 ▶ my $text = $fmt =~ /%/ ? sprintf($fmt, $n, $p, $base, $file // '', @$more) : $fmt;
Branch: 1 branch
BranchTrueFalseTotal
$fmt =~ /%/u ? : 177 3 180
Condition50%1/2
$file // ""
l!l
1770
MC/DC0%0/1
$file // ""
$file
Truth table50%1/2
A
A= $file
Aresult
11
00
749 180 ▶ next if $spec->[2] and $text !~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $spec->[2] and not $text =~ /\S/u 22 158 180
Condition100%3/3
$spec->[2] and not $text =~ /\S/u
!ll&&!rl&&r
1332522
MC/DC100%2/2
$spec->[2] and not $text =~ /\S/u
$spec->[2] not $text =~ /\S/u
Truth table100%3/3
A and not(B)
A= $spec->[2]B= not $text =~ /\S/u
ABresult
0X0
100
111
750 158 my $lw = ansi_width($text);
751 158 my $pos = $pos_fn->($spec->[0], $lw);
752 # A label in the middle grows to the left first, when its number
753 # gets a digit more, then to the right, and so on. It is placed
754 # from the narrowest one, that of the first pane and page: a
755 # label longer than that by one is longer on the left.
756 158 ▶ if ($spec == ($center // 0) and $fmt =~ /%/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec == ($center // 0) and $fmt =~ /%/u) 142 16 158
Condition100%5/5
$spec == ($center // 0) and $fmt =~ /%/u
!ll&&!rl&&r
133142
$center // 0
l!l
14513
MC/DC100%2/2
$spec == ($center // 0) and $fmt =~ /%/u
$spec == ($center // 0) $fmt =~ /%/u
MC/DC100%1/1
$center // 0
$center
Truth table100%3/3
A and B
A= $spec == ($center // 0)B= $fmt =~ /%/u
ABresult
0X0
100
111
Truth table100%2/2
A
A= $center
Aresult
11
00
757 142 ▶ my $narrow = ansi_width(sprintf $fmt, 1, 1, $base, $file // '', @$more);
Condition50%1/2
$file // ""
l!l
1420
MC/DC0%0/1
$file // ""
$file
Truth table50%1/2
A
A= $file
Aresult
11
00
758 142 ▶ $pos = $pos_fn->($spec->[0], $narrow) - int(($lw - $narrow + 1) / 2)
Branch: 1 branch
BranchTrueFalseTotal
if $lw > $narrow 95 47 142
759 if $lw > $narrow;
760 }
761 158 my $label = $obj->color('BORDER_LABEL', $text);
762 158 $str = ansi_substr($str, $pos, $lw, $label);
763 }
764 169 $str;
765 }
766  
767 106 ▶sub _column_out {
Subroutine _column_out: called CC=15 SCAR=27.2
768 106 my $obj = shift;
769  
770 106 my %bd = map { $_ => $obj->get_border($_) } qw(top bottom);
771  
772 106 ▶ my $bl = $obj->{_bl} //= _parse_labels($obj->label);
Condition33%1/3
$obj->{"_bl"} //= _parse_labels($obj->label)
l!l&&r!l&&!r
01060
MC/DC0%0/2
$obj->{"_bl"} //= _parse_labels($obj->label)
$obj->{"_bl"} _parse_labels($obj->label)
Truth table33%1/3
A //= B
A= $obj->{"_bl"}B= _parse_labels($obj->label)
ABresult
1X1
011
000
773 106 ▶ my $pbl = $obj->{_pbl} //= _parse_labels($obj->page_label);
Condition33%1/3
$obj->{"_pbl"} //= _parse_labels($obj->page_label)
l!l&&r!l&&!r
01060
MC/DC0%0/2
$obj->{"_pbl"} //= _parse_labels($obj->page_label)
$obj->{"_pbl"} _parse_labels($obj->page_label)
Truth table33%1/3
A //= B
A= $obj->{"_pbl"}B= _parse_labels($obj->page_label)
ABresult
1X1
011
000
774  
775 # pre-build pane label closures per pane index
776 106 my(@pane_top, @pane_bottom, @page_top, @page_bottom);
777 106 my($bw_l, $bw_c, $bw_r);
778 106 ▶ if ($bl || $pbl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bl or $pbl) 19 87 106
Condition100%3/3
$bl or $pbl
l!l&&r!l&&!r
15487
MC/DC100%2/2
$bl or $pbl
$bl $pbl
Truth table100%3/3
A or B
A= $blB= $pbl
ABresult
1X1
011
000
779 19 $bw_l = ansi_width($obj->get_border('left', 0));
780 19 $bw_c = ansi_width($obj->get_border('center', 0));
781 19 $bw_r = ansi_width($obj->get_border('right', 0));
782 19 my $span = $obj->{span};
783 19 for my $set ([ \@pane_top, \@page_top, qw(nw n ne) ],
784 [ \@pane_bottom, \@page_bottom, qw(sw s se) ]) {
785 38 my($pane_list, $page_list, @keys) = @$set;
786 38 ▶ if ($bl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bl) 30 8 38
787 30 my @g = map { $bl->{$_} } @keys;
788 30 ▶ if (grep { $_ } @g) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_;} @g) 17 13 30
789 17 my $fp = $bw_l;
790 17 for my $i (0 .. $obj->panes - 1) {
791 33 my($fs, $fe) = ($fp, $fp + $span);
792 153 ▶ push @$pane_list, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
793 153 my($line, $n0, $p, $name, $npanes) = @_;
794 153 $obj->_overlay_labels($line, $fs, $fe, $bw_l, $bw_r,
795 $n0 + $i + 1, $p, $name,
796 $obj->_label_more($p, $i, $npanes), @g);
797 33 };
798 33 $fp += $span + $bw_c;
799 }
800 }
801 }
802 38 ▶ if ($pbl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pbl) 8 30 38
803 8 my @g = map { $pbl->{$_} } @keys;
804 8 ▶ if (grep { $_ } @g) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_;} @g) 4 4 8
805 16 ▶ push @$page_list, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
806 16 my($line, $n0, $p, $name) = @_;
807 16 my $w = ansi_width($line);
808 16 $obj->_overlay_labels($line, 1, $w - 1, 1, 1,
809 $n0 + 1, $p, $name,
810 $obj->_label_more($p), @g);
811 4 };
812 }
813 }
814 }
815 }
816  
817 106 ▶ my $has_labels = @pane_top || @pane_bottom || @page_top || @page_bottom;
Condition88%8/9
@pane_top || @pane_bottom || @page_top || @page_bottom
l!l&&r!l&&!r
15487
@pane_top or @pane_bottom or @page_top
l!l&&r!l&&!r
15091
@pane_top or @pane_bottom
l!l&&r!l&&!r
11491
MC/DC75%3/4
@pane_top || @pane_bottom || @page_top || @page_bottom
@pane_top @pane_bottom @page_top @page_bottom
Truth table80%4/5
A or B or C || D
A= @pane_topB= @pane_bottomC= @page_topD= @page_bottom
ABCDresult
1XXX1
01XX1
001X1
00011
00000
818  
819 # pre-build border strings for 3 positions (top=0, middle=1, bottom=2)
820 106 my %border;
821 106 for my $pos (0, 1, 2) {
822 318 $border{$pos} = {
823 left => $obj->color_border('left', $pos),
824 center => $obj->color_border('center', $pos),
825 right => $obj->color_border('right', $pos),
826 };
827 }
828  
829 492 ▶ my $print_border = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
830 492 my($side, $pos, $span, $npanes, $n0, $p, $names,
831 $pane_labels, $page_labels) = @_;
832 492 ▶ return unless $bd{$side};
Branch: 1 branch
BranchTrueFalseTotal
unless $bd{$side} 162 330 492
833 330 my $bd = $border{$pos};
834 my $line = join '',
835 $bd->{left},
836 join($bd->{center},
837 404 map { $obj->color('BORDER', $bd{$side} x $_) } @$span),
838 330 $bd->{right};
839 330 ▶ if (@$pane_labels) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$pane_labels) 134 196 330
840 134 my $i = 0;
841 134 for (@{$pane_labels}[0 .. $npanes - 1]) {
842 153 ▶ $line = $_->($line, $n0, $p, $names->[$i++] // '', $npanes);
Condition50%1/2
$$names[$i++] // ""
l!l
1530
MC/DC0%0/1
$$names[$i++] // ""
$$names[$i++]
Truth table50%1/2
A
A= $$names[$i++]
Aresult
11
00
843 }
844 }
845 330 ▶ $line = $_->($line, $n0, $p, $names->[0] // '') for @$page_labels;
Condition50%1/2
$names->[0] // ""
l!l
160
MC/DC0%0/1
$names->[0] // ""
$names->[0]
Truth table50%1/2
A
A= $names->[0]
Aresult
11
00
846 330 print $line, "\n";
847 106 };
848  
849 246 ▶ sub {
Subroutine __ANON__: called CC=13 SCAR=25.7
850 246 ▶ my $opt = ref $_[0] eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 246 0 246
851 246 ▶ my @span = $opt->{span} ? @{$opt->{span}} : (($obj->{span}) x @_);
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'span'} ? : 19 227 246
852 246 ▶ my $page = $obj->current_page // 0;
Condition50%1/2
$obj->current_page // 0
l!l
2460
MC/DC0%0/1
$obj->current_page // 0
$obj->current_page
Truth table50%1/2
A
A= $obj->current_page
Aresult
11
00
853 246 my $npanes = scalar @_;
854  
855 246 ▶ my($n0, $p) = $has_labels
Branch: 1 branch
BranchTrueFalseTotal
$has_labels ? : 147 99 246
Condition50%1/2
$obj->panes // 1
l!l
1470
MC/DC0%0/1
$obj->panes // 1
$obj->panes
Truth table50%1/2
A
A= $obj->panes
Aresult
11
00
856 ? ($page * ($obj->panes // 1), $page + 1) : ();
857 246 ▶ my $names = $opt->{names} // [];
Condition50%1/2
$opt->{"names"} // []
l!l
2460
MC/DC0%0/1
$opt->{"names"} // []
$opt->{"names"}
Truth table50%1/2
A
A= $opt->{"names"}
Aresult
11
00
858  
859 246 $print_border->('top', 0, \@span, $npanes, $n0, $p, $names,
860 \@pane_top, \@page_top);
861  
862 # content rows
863 246 my $max = max map $#{$_}, @_;
864 246 for my $i (0 .. $max) {
865 my $pos = !$bd{top} && $i == 0 ? 0
866 882 ▶ : !$bd{bottom} && $i == $max ? 2
Branch: 2 branches
BranchTrueFalseTotal
!$bd{'top'} && $i == 0 ? : 81 801 882
!$bd{'bottom'} && $i == $max ? : 71 730 801
Condition100%6/6
not $bd{"top"} and $i == 0
!ll&&!rl&&r
62417781
not $bd{"bottom"} and $i == $max
!ll&&!rl&&r
62410671
MC/DC100%2/2
not $bd{"top"} and $i == 0
not $bd{"top"} $i == 0
MC/DC100%2/2
not $bd{"bottom"} and $i == $max
not $bd{"bottom"} $i == $max
Truth table100%3/3
not(A) and B
A= not $bd{"top"}B= $i == 0
ABresult
0X0
100
111
Truth table100%3/3
not(A) and B
A= not $bd{"bottom"}B= $i == $max
ABresult
0X0
100
111
867 : 1;
868 882 my $bd = $border{$pos};
869 882 my @span = @span;
870 my @panes = map {
871 882 ▶ @$_ ? ansi_sprintf("%-*s", shift @span, shift @$_) : ();
Branch: 1 branch
BranchTrueFalseTotal
@$_ ? : 1410 32 1442
872 } @_;
873 882 print $bd->{left};
874 print join $bd->{center},
875 882 map { $obj->color('TEXT', $_) } @panes;
876 882 print $bd->{right};
877 882 print "\n";
878 }
879  
880 246 $print_border->('bottom', 2, \@span, $npanes, $n0, $p, $names,
881 \@pane_bottom, \@page_bottom);
882 246 $obj;
883 106 };
884 }
885  
886 231 ▶sub _numbers {
Subroutine _numbers: called CC=1 SCAR=0.0
887 231 require Getopt::EX::Numbers;
888 231 Getopt::EX::Numbers->new(min => 1, @_);
889 }
890  
891 138 ▶sub table_out {
Subroutine table_out: called CC=60 SCAR=41.2
Pod undocumented
892 138 my $obj = shift;
893 138 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 137 138
894 # A LINE SEPARATOR is not a space between columns: it breaks a cell.
895 137 my $space = qr/[^\S\x{2028}]/;
896 137 my $split = do {
897 137 ▶ if ($obj->separator eq ' ') {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->separator eq ' ') { } 11 126 137
elsif ($obj->regex_sep) { } 0 126 126
898 # /\s+/a does not work as expected, maybe perl's bug
899 11 ▶ $obj->ignore_space ? ' ' : qr/\s{1,9999}/a;
Branch: 1 branch
BranchTrueFalseTotal
$obj->ignore_space ? : 11 0 11
900 } elsif ($obj->regex_sep) {
901 0 qr($obj->{separator});
902 } else {
903 126 qr/[\Q$obj->{separator}\E]/;
904 }
905 };
906 my @lines = map {
907 # split ' ' takes a LINE SEPARATOR as a space: do as it does,
908 # without it
909 137 ▶ $split eq ' ' && /\x{2028}/
Branch: 1 branch
BranchTrueFalseTotal
$split eq ' ' && /\x{2028}/u ? : 1 405 406
Condition100%3/3
$split eq " " and /\x{2028}/u
!ll&&!rl&&r
343621
MC/DC100%2/2
$split eq " " and /\x{2028}/u
$split eq " " /\x{2028}/u
Truth table100%3/3
A and B
A= $split eq " "B= /\x{2028}/u
ABresult
0X0
100
111
910 ? [ split /$space+/, s/\A$space+//r, $obj->table_columns_limit ]
911 : [ split $split, $_, $obj->table_columns_limit ];
912 } @_;
913 137 ▶ if (my $spec = $obj->table_remove) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = $obj->table_remove) 112 25 137
914 112 my $max_cols = max map { scalar @$_ } @lines;
915 224 my %discard = map { ($_ - 1) => 1 }
916 112 map { _numbers(max => $max_cols)->parse($_)->sequence }
917 split /,/, $spec;
918 112 my @keep = grep { !$discard{$_} } 0 .. $max_cols - 1;
919 112 @$_ = @$_[@keep] for @lines;
920 }
921 137 ▶ if ($obj->table_squeeze) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->table_squeeze) 1 136 137
922 5 ▶ my @keep = grep { my $c = $_; any { length $_->[$c] } @lines }
Subroutine __ANON__: called CC=1 SCAR=0.0
923 1 0 .. max(map { $#$_ } @lines);
924 1 @$_ = @$_[@keep] for @lines;
925 }
926 #
927 # -w / --cell: fit table into width, wrapping over-wide cells
928 #
929 137 my @fixed_width;
930 my @continued; # [row][col] 1 for a wrapped cell's 2nd+ line,
931 # 2 for a line after a LINE SEPARATOR
932 137 my @length; # [row][col] width of the cell
933 137 ▶ if (not $obj->table_align and not $obj->table_tabs
Branch: 2 branches
BranchTrueFalseTotal
if (not $obj->table_align || $obj->table_tabs and defined $obj->width || $obj->cell) { } 108 29 137
elsif (grep {/\x{2028}/u;} map({@$_;} @lines)) { } 9 20 29
Condition88%8/9
not $obj->table_align || $obj->table_tabs and defined $obj->width || $obj->cell
!ll&&!rl&&r
425108
$obj->table_align || $obj->table_tabs
l!l&&r!l&&!r
40133
defined $obj->width or $obj->cell
l!l&&r!l&&!r
961225
MC/DC75%3/4
not $obj->table_align || $obj->table_tabs and defined $obj->width || $obj->cell
$obj->table_align $obj->table_tabs defined $obj->width $obj->cell
Truth table80%4/5
not(A || B) and C or D
A= $obj->table_alignB= $obj->table_tabsC= defined $obj->widthD= $obj->cell
ABCDresult
1XXX0
01XX0
00000
001X1
00011
934 and (defined $obj->width or $obj->cell)) {
935 108 my @cw = map { [ map { cell_width($_) } @$_ ] } @lines;
936 108 my @content = map { max @$_ } xpose @cw;
937 108 ▶ my $overhead = $obj->item_format ? ansi_width(ansi_sprintf($obj->item_format, '')) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$obj->item_format ? : 78 30 108
938 108 my $sep = ansi_width($obj->output_separator);
939 108 ▶ my $fixed = $obj->cell ? parse_cell_spec($obj->cell, \@content) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj->cell ? : 13 95 108
940 108 ▶ my $budget = defined $obj->width ? $obj->get_width - $sep * (@content - 1) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $obj->width ? : 96 12 108
941 108 @lines = $obj->fit_table_rows(\@lines, \@cw, \@content, $budget, $overhead, $fixed, 4, \@continued, \@length);
942 108 ▶ @fixed_width = map { defined $_ ? $_ + $overhead : undef } @$fixed if $fixed;
Branch: 2 branches
BranchTrueFalseTotal
if $fixed 13 95 108
defined $_ ? : 18 7 25
943 }
944 630 elsif (grep { /\x{2028}/ } map { @$_ } @lines) {
945 # no wrapping, but a cell has lines
946 9 my @cw = map { [ map { cell_width($_) } @$_ ] } @lines;
947 9 @lines = $obj->expand_table_rows(\@lines, \@cw, [], [], \@continued, \@length);
948 }
949 137 my @blank = map { [ map { $_ eq '' } @$_ ] } @lines;
950 137 ▶ @length = map { [ map { ansi_width $_ } @$_ ] } @lines unless @length;
Branch: 1 branch
BranchTrueFalseTotal
unless @length 20 117 137
951 137 ▶ if (my $fmt = $obj->item_format) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fmt = $obj->item_format) 84 53 137
952 # A format with a single %s only adds text around the cell, so
953 # it is put by hand and the width of the text is added.
954 84 ▶ if (my($pre, $post) = $fmt =~ /\A([^%]*+)%s([^%]*+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $fmt =~ /\A([^%]*+)%s([^%]*+)\z/u) { } 84 0 84
955 84 my $add = ansi_width($pre . $post);
956 84 for my $r (keys @lines) {
957 1151 my $line = $lines[$r];
958 1151 for my $c (keys @$line) {
959 5491 ▶ $line->[$c] = defined $line->[$c] ? "$pre$line->[$c]$post" : ansi_sprintf($fmt, undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $line->[$c] ? : 5491 0 5491
960 5491 $length[$r][$c] += $add;
961 }
962 }
963 } else {
964 0 for my $line (@lines) {
965 0 @$line = map { ansi_sprintf($fmt, $_) } @$line;
966 }
967 0 @length = map { [ map { ansi_width $_ } @$_ ] } @lines;
968 }
969 }
970 #
971 # --table-wrap-mark: put the mark where a continuation line starts,
972 # in place of leading pad as far as the mark is wide. A line which
973 # starts after a LINE SEPARATOR is not a continuation and has none.
974 # --table-cell-mark: same for the first line of every non-empty cell
975 # in a column that has a wrapped cell, so that a row start can be
976 # told from a continuation line; the first --table-head rows (a
977 # wrapped row counting as one) are a header and get no mark.
978 #
979 137 my @marked; # [row][col] mark string, for alignment below
980 42 ▶ my $put_mark = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
981 42 my($mark, $r, $c) = @_;
982 42 my $mw = ansi_width($mark);
983 42 $lines[$r][$c] =~ s/^\h{0,$mw}/$mark/;
984 42 $length[$r][$c] = ansi_width($lines[$r][$c]);
985 42 $marked[$r][$c] = $mark;
986 137 };
987 137 ▶ if ((my $mark = $obj->table_wrap_mark) ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $mark = $obj->table_wrap_mark) ne "") 6 131 137
988 6 for my $r (grep { $continued[$_] } keys @continued) {
989 9 ▶ $put_mark->($mark, $r, $_) for grep { ($continued[$r][$_] // 0) == 1 } keys @{$continued[$r]};
Condition100%2/2
$continued[$r][$_] // 0
l!l
99
MC/DC100%1/1
$continued[$r][$_] // 0
$continued[$r][$_]
Truth table100%2/2
A
A= $continued[$r][$_]
Aresult
11
00
990 }
991 }
992 137 ▶ if ((my $mark = $obj->table_cell_mark) ne '' and grep { $_ } @continued) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $mark = $obj->table_cell_mark) ne "" and grep {$_;} @continued) 14 123 137
Condition100%3/3
(my $mark = $obj->table_cell_mark) ne "" and grep {$_;} @continued
!ll&&!rl&&r
121214
MC/DC100%2/2
(my $mark = $obj->table_cell_mark) ne "" and grep {$_;} @continued
(my $mark = $obj->table_cell_mark) ne "" grep {$_;} @continued
Truth table100%3/3
A and B
A= (my $mark = $obj->table_cell_mark) ne ""B= grep {$_;} @continued
ABresult
0X0
100
111
993 14 my %wrapped;
994 14 for my $r (grep { $continued[$_] } keys @continued) {
995 23 $wrapped{$_}++ for grep { $continued[$r][$_] } keys @{$continued[$r]};
996 }
997 14 my $row = 0; # logical row number of a non-continuation line
998 14 for my $r (grep { not $continued[$_] } keys @lines) {
999 38 ▶ next if $row++ < $obj->table_head;
Branch: 1 branch
BranchTrueFalseTotal
if $row++ < $obj->table_head 6 32 38
1000 32 ▶ $put_mark->($mark, $r, $_) for grep { $wrapped{$_} and not $blank[$r][$_] } keys @{$lines[$r]};
Condition66%2/3
$wrapped{$_} && !$blank[$r][$_]
!ll&&!rl&&r
30034
MC/DC50%1/2
$wrapped{$_} && !$blank[$r][$_]
$wrapped{$_} !$blank[$r][$_]
Truth table66%2/3
A && not(B)
A= $wrapped{$_}B= !$blank[$r][$_]
ABresult
0X0
100
111
1001 }
1002 }
1003 137 my @max = map { max @$_ } xpose @length;
1004 137 for my $i (grep { defined $fixed_width[$_] } keys @fixed_width) {
1005 18 ▶ $max[$i] = max($max[$i] // 0, $fixed_width[$i]);
Condition50%1/2
$max[$i] // 0
l!l
180
MC/DC0%0/1
$max[$i] // 0
$max[$i]
Truth table50%1/2
A
A= $max[$i]
Aresult
11
00
1006 }
1007 137 ▶ if ($obj->table_align) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->table_align) 4 133 137
1008 4 my @tabs = map { roundup $_, $obj->column_unit, $obj->margin } @max;
1009 #
1010 # --table-tabs
1011 #
1012 4 ▶ if ($obj->table_tabs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->table_tabs) 1 3 4
1013 1 my $cu = $obj->column_unit;
1014 1 ▶ while (my($lx, $l) = each @lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @lines) 10 1 11
1015 10 ▶ while (my($fx, $f) = each @$l) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$l) 100 10 110
1016 100 print $f;
1017 100 ▶ if ($fx == $#{$l}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fx == $#{$l;}) { } 10 90 100
1018 10 print "\n";
1019 } else {
1020 90 print "\t" x div($tabs[$fx] - $length[$lx][$fx], $cu);
1021 }
1022 }
1023 }
1024 1 return $obj;
1025 }
1026 3 @max = map { $_ - $obj->margin } @tabs;
1027 3 $obj->output_separator = ' ' x $obj->margin;
1028 }
1029 my @align = newlist(count => int @max, default => '-',
1030 [ map --$_, map {
1031 5 _numbers(max => int @max)->parse($_)->sequence
1032 } split /,/, $obj->table_right ] => '',
1033 [ map --$_, map {
1034 136 _numbers(max => int @max)->parse($_)->sequence
1035 } split /,/, $obj->table_center ] => '=');
1036 136 ▶ my @format = map { $align[$_] eq '=' ? "%-$max[$_]s" : "%$align[$_]$max[$_]s" } keys @max;
Branch: 1 branch
BranchTrueFalseTotal
$align[$_] eq '=' ? : 2 495 497
1037 136 for my $r (keys @lines) {
1038 1484 my $line = $lines[$r];
1039 1484 ▶ next unless @$line;
Branch: 1 branch
BranchTrueFalseTotal
unless @$line 0 1484 1484
1040 1484 for my $i (keys @$line) {
1041 # Pad right/center aligned cells here, keeping a mark at the
1042 # left edge of the cell rather than in front of the content.
1043 6511 ▶ next if $align[$i] eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $align[$i] eq "-" 6444 67 6511
1044 67 my $pad = $max[$i] - $length[$r][$i];
1045 67 ▶ next if $pad <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pad <= 0 34 33 67
1046 33 ▶ $pad = int($pad / 2) if $align[$i] eq '=';
Branch: 1 branch
BranchTrueFalseTotal
if $align[$i] eq "=" 8 25 33
1047 33 $line->[$i] = (' ' x $pad) . $line->[$i];
1048 33 $length[$r][$i] += $pad;
1049 33 ▶ if (my $mark = $marked[$r][$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mark = $marked[$r][$i]) 7 26 33
1050 7 $line->[$i] =~ s/^(\h+)\Q$mark\E/$mark$1/;
1051 }
1052 }
1053 1484 my @fmt = @format[keys @$line];
1054 1484 ▶ $fmt[$#fmt] = '%s' if $align[$#fmt] ne '' and !$obj->padding;
Branch: 1 branch
BranchTrueFalseTotal
if $align[$#fmt] ne "" and not $obj->padding 1449 35 1484
Condition100%3/3
$align[$#fmt] ne "" and not $obj->padding
!ll&&!rl&&r
2871449
MC/DC100%2/2
$align[$#fmt] ne "" and not $obj->padding
$align[$#fmt] ne "" not $obj->padding
Truth table100%3/3
A and not(B)
A= $align[$#fmt] ne ""B= not $obj->padding
ABresult
0X0
100
111
1055 1484 ▶ if (grep { not defined } @$line) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not defined $_;} @$line) 0 1484 1484
1056 0 my $format = join($obj->output_separator, @fmt) . "\n";
1057 0 ansi_printf $format, @$line;
1058 0 next;
1059 }
1060 # the width of every cell is known: pad it here
1061 my @out = map {
1062 1484 my $space = ' ' x ($max[$_] - $length[$r][$_]);
1063 6511 ▶ $fmt[$_] eq '%s' ? $line->[$_]
Branch: 2 branches
BranchTrueFalseTotal
$fmt[$_] eq '%s' ? : 1449 5062 6511
$align[$_] eq '' ? : 58 5004 5062
1064 : $align[$_] eq '' ? $space . $line->[$_]
1065 : $line->[$_] . $space;
1066 } keys @$line;
1067 1484 print join($obj->output_separator, @out), "\n";
1068 }
1069 136 return $obj;
1070 }
1071  
1072 253 1;
1073  
1074 __END__
↑ Summary lib/App/ansicolumn/Table.pm »