Text/ANSITable.pm

filter: Statementstmt 63.8% 611 / 957 Branchbran 36.9% 145 / 392 Conditioncond 32.0% 77 / 240 MC/DCmcdc 1.6% 2 / 121 Subroutinesub 75.6% 56 / 74 Podpod 80.6% 25 / 31 totaltotal 50.4% 916 / 1815 CC 356 SCAR 41.7
CC
356
Cov
52%
_read_style_envs
314.7
_adjust_column_widths
230.9
BUILD
177.3
CRAP 64.7
↑ Summary Text/ANSITable/StyleSet/AltRow.pm »
1 package Text::ANSITable;
2  
3 3 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use ColorThemeUtil::ANSI qw(item_color_to_ansi);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 #use List::Util qw(first);
10 3 ▶use Scalar::Util 'looks_like_number';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 require # hide from cpanspec
12 3 ▶ Win32::Console::ANSI if $^O =~ /Win/;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /Win/ 0 3 3
13  
14 3 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
15 3 our $DATE = '2025-02-24'; # DATE
16 3 our $DIST = 'Text-ANSITable'; # DIST
17 3 our $VERSION = '0.610'; # VERSION
18  
19 # see Module::Features for more details on this
20 3 our %FEATURES = (
21 set_v => {
22 TextTable => 1,
23 },
24  
25 features => {
26 PerlTrove => {
27 "Development Status" => "5 - Production/Stable",
28 "Environment" => "Console",
29 # Framework
30 "Intended Audience" => ["Developers"],
31 "License" => "OSI Approved :: Artistic License",
32 # Natural Language
33 # Operating System
34 "Programming Language" => "Perl",
35 "Topic" => ["Software Development :: Libraries :: Perl Modules", "Utilities"],
36 # Typing
37 },
38  
39 TextTable => {
40 can_align_cell_containing_wide_character => 1,
41 can_align_cell_containing_color_code => 1,
42 can_align_cell_containing_newline => 1,
43 can_use_box_character => 1,
44 can_customize_border => 1,
45 can_halign => 1,
46 can_halign_individual_row => 1,
47 can_halign_individual_column => 1,
48 can_halign_individual_cell => 1,
49 can_valign => 1,
50 can_valign_individual_row => 1,
51 can_valign_individual_column => 1,
52 can_valign_individual_cell => 1,
53 can_rowspan => 0,
54 can_colspan => 0,
55 can_color => 1,
56 can_color_theme => 1,
57 can_set_cell_height => 1,
58 can_set_cell_height_of_individual_row => 1,
59 can_set_cell_width => 1,
60 can_set_cell_width_of_individual_column => 1,
61 speed => 'slow',
62 can_hpad => 1,
63 can_hpad_individual_row => 1,
64 can_hpad_individual_column => 1,
65 can_hpad_individual_cell => 1,
66 can_vpad => 1,
67 can_vpad_individual_row => 1,
68 can_vpad_individual_column => 1,
69 can_vpad_individual_cell => 1,
70 },
71 },
72 );
73  
74 3 my $ATTRS = [qw(
75  
76 use_color color_depth use_box_chars use_utf8 columns rows
77 column_filter row_filter show_row_separator show_header
78 show_header cell_width cell_height cell_pad cell_lpad
79 cell_rpad cell_vpad cell_tpad cell_bpad cell_fgcolor
80 cell_bgcolor cell_align cell_valign header_align header_valign
81 header_vpad header_tpad header_bpad header_fgcolor
82 header_bgcolor
83  
84 )];
85 3 my $STYLES = $ATTRS;
86 3 my $COLUMN_STYLES = [qw(
87  
88 type width align valign pad lpad rpad formats fgcolor
89 bgcolor wrap
90  
91 )];
92 3 my $ROW_STYLES = [qw(
93  
94 height align valign vpad tpad bpad fgcolor bgcolor
95  
96 )];
97 3 my $CELL_STYLES = [qw(
98  
99 align valign formats fgcolor bgcolor
100  
101 )];
102  
103 has border_style => (
104 is => 'rw',
105 3 ▶ trigger => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
106 3 require Module::Load::Util;
107 3 my ($self, $val) = @_;
108 $self->{border_style_obj} =
109 3 Module::Load::Util::instantiate_class_with_optional_args(
110 {ns_prefixes=>['BorderStyle::Text::ANSITable', 'BorderStyle', 'BorderStyle::Text::ANSITable::OldCompat']}, $val);
111 },
112 3 );
113  
114 has color_theme => (
115 is => 'rw',
116 3 ▶ trigger => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
117 3 require Module::Load::Util;
118 3 my ($self, $val) = @_;
119 $self->{color_theme_obj} =
120 3 Module::Load::Util::instantiate_class_with_optional_args(
121 {ns_prefixes=>['ColorTheme::Text::ANSITable', 'ColorTheme', 'ColorTheme::Text::ANSITable::OldCompat']}, $val);
122 },
123 3 );
124  
125 has columns => (
126 is => 'rw',
127 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
128 3 ▶ trigger => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
129 3 my $self = shift;
130  
131 # check that column names are unique
132 3 my %seen;
133 3 ▶ for (@{$_[0]}) { die "Duplicate column name '$_'" if $seen{$_}++ }
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$_}++ 1 6 7
134  
135 2 $self->{_columns_set}++;
136 },
137 3 );
138 has rows => (
139 is => 'rw',
140 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
141 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
142 0 my ($self, $rows) = @_;
143 0 $self->_set_default_cols($rows->[0]);
144 },
145 3 );
146 3 has column_filter => (
147 is => 'rw',
148 );
149 3 has column_wrap => (
150 is => 'rw',
151 );
152 3 has row_filter => (
153 is => 'rw',
154 );
155 has _row_separators => ( # [index after which sep should be drawn, ...] sorted
156 is => 'rw',
157 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
158 3 );
159 has show_row_separator => (
160 is => 'rw',
161 3 ▶ default => sub { 2 },
Subroutine __ANON__: called CC=1 SCAR=0.0
162 3 );
163 has show_header => (
164 is => 'rw',
165 3 ▶ default => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
166 3 );
167  
168 has _column_styles => ( # store per-column styles
169 is => 'rw',
170 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
171 3 );
172 has _row_styles => ( # store per-row styles
173 is => 'rw',
174 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
175 3 );
176 has _cell_styles => ( # store per-cell styles
177 is => 'rw',
178 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
179 3 );
180  
181 # each element of _cond_*styles is a two-element [$cond, ], where $cond is code
182 # (str|coderef) and the second element is a hashref containing styles.
183  
184 has _cond_column_styles => ( # store conditional column styles
185 is => 'rw',
186 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
187 3 );
188 has _cond_row_styles => ( # store conditional row styles
189 is => 'rw',
190 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
191 3 );
192 has _cond_cell_styles => ( # store conditional cell styles
193 is => 'rw',
194 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
195 3 );
196  
197 3 has cell_width => (
198 is => 'rw',
199 );
200 3 has cell_height => (
201 is => 'rw',
202 );
203 has cell_pad => (
204 is => 'rw',
205 3 ▶ default => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
206 3 );
207 3 has cell_lpad => (
208 is => 'rw',
209 );
210 3 has cell_rpad => (
211 is => 'rw',
212 );
213 has cell_vpad => (
214 is => 'rw',
215 3 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
216 3 );
217 3 has cell_tpad => (
218 is => 'rw',
219 );
220 3 has cell_bpad => (
221 is => 'rw',
222 );
223 3 has cell_fgcolor => (
224 is => 'rw',
225 );
226 3 has cell_bgcolor => (
227 is => 'rw',
228 );
229 3 has cell_align => (
230 is => 'rw',
231 );
232 3 has cell_valign => (
233 is => 'rw',
234 );
235  
236 3 has header_align => (
237 is => 'rw',
238 );
239 3 has header_valign => (
240 is => 'rw',
241 );
242 3 has header_vpad => (
243 is => 'rw',
244 );
245 3 has header_tpad => (
246 is => 'rw',
247 );
248 3 has header_bpad => (
249 is => 'rw',
250 );
251 3 has header_fgcolor => (
252 is => 'rw',
253 );
254 3 has header_bgcolor => (
255 is => 'rw',
256 );
257  
258 3 with 'Term::App::Role::Attrs';
259  
260 8 ▶sub _color_theme_item_color_to_ansi {
Subroutine _color_theme_item_color_to_ansi: called CC=3 SCAR=12.0
261 8 my ($self, $item, $args, $is_bg) = @_;
262 item_color_to_ansi(
263 8 ▶ ($self->{color_theme_obj}->get_item_color($item, $args) // undef), # because sometimes get_item_color() might return an empty list
Condition50%2/4
item_color_to_ansi($self->{"color_theme_obj"}->get_item_color($item, $args) // undef, $is_bg) // ""
l!l
08
$self->{"color_theme_obj"}->get_item_color($item, $args) // undef
l!l
08
MC/DC0%0/1
item_color_to_ansi($self->{"color_theme_obj"}->get_item_color($item, $args) // undef, $is_bg) // ""
item_color_to_ansi($self->{"color_theme_obj"}->get_item_color($item, $args) // undef, $is_bg)
MC/DC0%0/1
$self->{"color_theme_obj"}->get_item_color($item, $args) // undef
$self->{"color_theme_obj"}->get_item_color($item, $args)
Truth table50%1/2
A
A= item_color_to_ansi($self->{"color_theme_obj"}->get_item_color($item, $args) // undef, $is_bg)
Aresult
11
00
Truth table50%1/2
A
A= $self->{"color_theme_obj"}->get_item_color($item, $args)
Aresult
11
00
264 $is_bg)
265 // '';
266 }
267  
268 3 ▶sub BUILD {
Subroutine BUILD: called CC=30 SCAR=51.8
Pod undocumented
269 3 my ($self, $args) = @_;
270  
271 3 ▶ if ($ENV{ANSITABLE_STYLE_SETS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ANSITABLE_STYLE_SETS"}) 0 3 3
272 0 require JSON::MaybeXS;
273 0 my $sets = JSON::MaybeXS::decode_json($ENV{ANSITABLE_STYLE_SETS});
274 0 ▶ croak "ANSITABLE_STYLE_SETS must be an array"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sets eq "ARRAY" 0 0 0
275 unless ref($sets) eq 'ARRAY';
276 0 for my $set (@$sets) {
277 0 ▶ if (ref($set) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $set eq 'ARRAY') { } 0 0 0
278 0 $self->apply_style_set($set->[0], $set->[1]);
279 } else {
280 0 $self->apply_style_set($set);
281 }
282 }
283 }
284  
285 3 ▶ if ($ENV{ANSITABLE_STYLE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ANSITABLE_STYLE"}) 0 3 3
286 0 require JSON::MaybeXS;
287 0 my $s = JSON::MaybeXS::decode_json($ENV{ANSITABLE_STYLE});
288 0 for my $k (keys %$s) {
289 0 my $v = $s->{$k};
290 croak "Unknown table style '$k' in ANSITABLE_STYLE environment, ".
291 "please use one of [".join(", ", @$STYLES)."]"
292 0 ▶ unless grep { $_ eq $k } @$STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $k;} @$STYLES 0 0 0
293 0 $self->{$k} = $v;
294 }
295 }
296  
297 # pick a default border style
298 3 ▶ unless ($self->{border_style}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"border_style"}) 3 0 3
299 3 my $bs;
300  
301 3 my $use_utf8 = $self->use_utf8;
302  
303 # even though Term::Detect::Software decides that linux virtual console
304 # does not support unicode, it actually can display some uni characters
305 # like single borders, so we use it as the default here instead of
306 # singleo_ascii (linux vc doesn't seem to support box_chars).
307 3 ▶ my $emu_eng = $self->detect_terminal->{emulator_engine} // '';
Condition50%1/2
$self->detect_terminal->{"emulator_engine"} // ""
l!l
30
MC/DC0%0/1
$self->detect_terminal->{"emulator_engine"} // ""
$self->detect_terminal->{"emulator_engine"}
Truth table50%1/2
A
A= $self->detect_terminal->{"emulator_engine"}
Aresult
11
00
308 3 ▶ my $linux_vc = $emu_eng eq 'linux' && !defined($ENV{UTF8});
Condition33%1/3
$emu_eng eq 'linux' && !defined($ENV{'UTF8'})
!ll&&!rl&&r
300
MC/DC0%0/2
$emu_eng eq 'linux' && !defined($ENV{'UTF8'})
$emu_eng eq 'linux' !defined($ENV{'UTF8'})
Truth table33%1/3
A && not(B)
A= $emu_eng eq 'linux'B= !defined($ENV{'UTF8'})
ABresult
0X0
100
111
309 3 ▶ if ($linux_vc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($linux_vc) 0 3 3
310 0 $use_utf8 = 1;
311 0 $bs = 'UTF8::SingleLineOuterOnly';
312 }
313 # use statement modifier style to avoid block and make local work
314 3 ▶ local $self->{use_utf8} = 1 if $linux_vc;
Branch: 1 branch
BranchTrueFalseTotal
if $linux_vc 0 3 3
315  
316 # we only default to utf8 border if user has set something like
317 # binmode(STDOUT, ":utf8") to avoid 'Wide character in print' warning.
318 3 ▶ unless (defined $ENV{UTF8}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ENV{"UTF8"}) 3 0 3
319 3 require PerlIO;
320 3 my @layers = PerlIO::get_layers(STDOUT);
321 3 ▶ $use_utf8 = 0 unless grep { $_ eq 'utf8' } @layers;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "utf8";} @layers 3 0 3
322 }
323  
324 3 ▶ if (defined $ENV{ANSITABLE_BORDER_STYLE}) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $ENV{'ANSITABLE_BORDER_STYLE'}) { } 0 3 3
elsif (defined $ENV{'BORDER_STYLE'}) { } 0 3 3
elsif ($use_utf8) { } 0 3 3
elsif ($self->use_box_chars) { } 0 3 3
325 0 $bs = $ENV{ANSITABLE_BORDER_STYLE};
326 } elsif (defined $ENV{BORDER_STYLE}) {
327 0 $bs = $ENV{BORDER_STYLE};
328 } elsif ($use_utf8) {
329 0 ▶ $bs //= 'UTF8::BrickOuterOnly';
Condition0%0/2
$bs //= "UTF8::BrickOuterOnly"
l!l
00
MC/DC0%0/1
$bs //= "UTF8::BrickOuterOnly"
$bs
Truth table0%0/2
A
A= $bs
Aresult
11
00
330 } elsif ($self->use_box_chars) {
331 0 $bs = 'BoxChar::SingleLineOuterOnly';
332 } else {
333 3 $bs = 'ASCII::SingleLineOuterOnly';
334 }
335  
336 3 $self->border_style($bs);
337 }
338  
339 # pick a default color theme
340 3 ▶ unless ($self->{color_theme}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"color_theme"}) 3 0 3
341 3 my $ct;
342 3 ▶ if (defined $ENV{ANSITABLE_COLOR_THEME}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ENV{'ANSITABLE_COLOR_THEME'}) { } 0 3 3
elsif ($self->use_color) { } 0 3 3
343 0 $ct = $ENV{ANSITABLE_COLOR_THEME};
344 } elsif ($self->use_color) {
345 0 ▶ my $bg = $self->detect_terminal->{default_bgcolor} // '';
Condition0%0/2
$self->detect_terminal->{"default_bgcolor"} // ""
l!l
00
MC/DC0%0/1
$self->detect_terminal->{"default_bgcolor"} // ""
$self->detect_terminal->{"default_bgcolor"}
Truth table0%0/2
A
A= $self->detect_terminal->{"default_bgcolor"}
Aresult
11
00
346 0 ▶ if ($self->color_depth >= 2**24) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->color_depth >= 16777216.0) { } 0 0 0
347 0 ▶ $ct = 'Standard::Gradation' .
Branch: 1 branch
BranchTrueFalseTotal
$bg eq 'ffffff' ? : 0 0 0
348 ($bg eq 'ffffff' ? 'WhiteBG' : '');
349 } else {
350 0 ▶ $ct = 'Standard::NoGradation' .
Branch: 1 branch
BranchTrueFalseTotal
$bg eq 'ffffff' ? : 0 0 0
351 ($bg eq 'ffffff' ? 'WhiteBG' : '');;
352 }
353 } else {
354 3 $ct = 'NoColor';
355 }
356 3 $self->color_theme($ct);
357 }
358  
359 3 ▶ unless (defined $self->{wide}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"wide"}) 3 0 3
360 3 ▶ $self->{wide} = eval { require Text::ANSI::WideUtil; 1 } ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Text::ANSI::WideUtil; 1 } } ? : 3 0 3
361 }
362 3 require Text::ANSI::Util;
363 3 $self->{_func_add_color_resets} = \&Text::ANSI::Util::ta_add_color_resets;
364 3 ▶ if ($self->{wide}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'wide'}) { } 3 0 3
365 3 require Text::ANSI::WideUtil;
366 3 $self->{_func_length_height} = \&Text::ANSI::WideUtil::ta_mbswidth_height;
367 3 $self->{_func_pad} = \&Text::ANSI::WideUtil::ta_mbpad;
368 3 $self->{_func_wrap} = \&Text::ANSI::WideUtil::ta_mbwrap;
369 } else {
370 0 $self->{_func_length_height} = \&Text::ANSI::Util::ta_length_height;
371 0 $self->{_func_pad} = \&Text::ANSI::Util::ta_pad;
372 0 $self->{_func_wrap} = \&Text::ANSI::Util::ta_wrap;
373 }
374 }
375  
376 1 ▶sub _set_default_cols {
Subroutine _set_default_cols: called CC=3 SCAR=16.5
377 1 my ($self, $row) = @_;
378 1 ▶ return if $self->{_columns_set}++;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_columns_set"}++ 1 0 1
379 0 ▶ $self->columns([map {"col$_"} 0..@$row-1]) if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 0 0 0
380 }
381  
382 7 ▶sub add_row {
Subroutine add_row: called CC=5 SCAR=17.3
Pod documented
383 7 my ($self, $row, $styles) = @_;
384 7 ▶ croak "Row must be arrayref" unless ref($row) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $row eq "ARRAY" 1 6 7
385 6 push @{ $self->{rows} }, $row;
386 6 ▶ $self->_set_default_cols($row) unless $self->{_columns_set}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_columns_set"}++ 1 5 6
387 6 ▶ if ($styles) {
Branch: 1 branch
BranchTrueFalseTotal
if ($styles) 0 6 6
388 0 my $i = @{ $self->{rows} }-1;
389 0 for my $s (keys %$styles) {
390 0 $self->set_row_style($i, $s, $styles->{$s});
391 }
392 }
393 6 $self;
394 }
395  
396 0 ▶sub add_row_separator {
Subroutine add_row_separator: not called CC=3 SCAR=24.8
Pod documented
397 0 my ($self) = @_;
398 0 my $idx = @{$self->{rows}}-1;
399 # ignore duplicate separators
400 0 push @{ $self->{_row_separators} }, $idx
401 0 unless @{ $self->{_row_separators} } &&
402 0 ▶ $self->{_row_separators}[-1] == $idx;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"_row_separators"};} and $self->{"_row_separators"}[-1] == $idx 0 0 0
Condition0%0/3
@{$self->{"_row_separators"};} and $self->{"_row_separators"}[-1] == $idx
!ll&&!rl&&r
000
MC/DC0%0/2
@{$self->{"_row_separators"};} and $self->{"_row_separators"}[-1] == $idx
@{$self->{"_row_separators"};} $self->{"_row_separators"}[-1] == $idx
Truth table0%0/3
A and B
A= @{$self->{"_row_separators"};}B= $self->{"_row_separators"}[-1] == $idx
ABresult
0X0
100
111
403 0 $self;
404 }
405  
406 2 ▶sub add_rows {
Subroutine add_rows: called CC=3 SCAR=11.0
Pod documented
407 2 my ($self, $rows, $styles) = @_;
408 2 ▶ croak "Rows must be arrayref" unless ref($rows) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rows eq "ARRAY" 1 1 2
409 1 $self->add_row($_, $styles) for @$rows;
410 1 $self;
411 }
412  
413 36 ▶sub _colnum {
Subroutine _colnum: called CC=4 SCAR=13.9
414 36 my $self = shift;
415 36 my $colname = shift;
416  
417 36 ▶ return $colname if looks_like_number($colname);
Branch: 1 branch
BranchTrueFalseTotal
if &looks_like_number($colname) 26 10 36
418 10 my $cols = $self->{columns};
419 10 for my $i (0..@$cols-1) {
420 14 ▶ return $i if $cols->[$i] eq $colname;
Branch: 1 branch
BranchTrueFalseTotal
if $cols->[$i] eq $colname 9 5 14
421 }
422 1 croak "Unknown column name '$colname'";
423 }
424  
425 6 ▶sub get_cell {
Subroutine get_cell: called CC=1 SCAR=0.0
Pod documented
426 6 my ($self, $rownum, $col) = @_;
427  
428 6 $col = $self->_colnum($col);
429  
430 5 $self->{rows}[$rownum][$col];
431 }
432  
433 1 ▶sub set_cell {
Subroutine set_cell: called CC=1 SCAR=0.0
Pod documented
434 1 my ($self, $rownum, $col, $val) = @_;
435  
436 1 $col = $self->_colnum($col);
437  
438 1 my $oldval = $self->{rows}[$rownum][$col];
439 1 $self->{rows}[$rownum][$col] = $val;
440 1 $oldval;
441 }
442  
443 0 ▶sub get_column_style {
Subroutine get_column_style: not called CC=1 SCAR=6.9
Pod documented
444 0 my ($self, $col, $style) = @_;
445  
446 0 $col = $self->_colnum($col);
447 0 $self->{_column_styles}[$col]{$style};
448 }
449  
450 0 ▶sub set_column_style {
Subroutine set_column_style: not called CC=4 SCAR=30.0
Pod documented
451 0 my $self = shift;
452 0 my $col = shift;
453  
454 0 $col = $self->_colnum($col);
455  
456 0 ▶ my %sets = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
457  
458 0 for my $style (keys %sets) {
459 0 my $val = $sets{$style};
460 croak "Unknown per-column style '$style', please use one of [".
461 0 ▶ join(", ", @$COLUMN_STYLES) . "]" unless grep { $_ eq $style } @$COLUMN_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $style;} @$COLUMN_STYLES 0 0 0
462 0 $self->{_column_styles}[$col]{$style} = $val;
463 }
464 }
465  
466 0 ▶sub get_cond_column_styles {
Subroutine get_cond_column_styles: not called CC=1 SCAR=6.9
Pod documented
467 0 my $self = shift;
468 0 $self->{_cond_column_styles};
469 }
470  
471 #sub set_cond_column_style {
472 # my ($self, $styles) = @_;
473 # $self->{_cond_column_styles} = $styles;
474 #}
475  
476 0 ▶sub add_cond_column_style {
Subroutine add_cond_column_style: not called CC=5 SCAR=34.0
Pod documented
477 0 my $self = shift;
478 0 my $cond = shift;
479 0 ▶ if (ref($cond) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cond ne "CODE") 0 0 0
480 0 croak "cond must be a coderef";
481 }
482  
483 0 my $styles;
484 0 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
485 0 $styles = shift;
486 } else {
487 0 $styles = { @_ };
488 }
489  
490 0 for my $style (keys %$styles) {
491 croak "Unknown per-column style '$style', please use one of [".
492 0 ▶ join(", ", @$COLUMN_STYLES) . "]" unless grep { $_ eq $style } @$COLUMN_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $style;} @$COLUMN_STYLES 0 0 0
493 }
494  
495 0 push @{ $self->{_cond_column_styles} }, [$cond, $styles];
496 }
497  
498 #sub clear_cond_column_styles {
499 # my $self = shift;
500 # $self->{_cond_column_styles} = [];
501 #}
502  
503 17 ▶sub get_eff_column_style {
Subroutine get_eff_column_style: called CC=9 SCAR=29.0
Pod documented
504 17 my ($self, $col, $style) = @_;
505  
506 17 $col = $self->_colnum($col);
507  
508 # the result of calculation is cached here
509 17 ▶ if (defined $self->{_draw}{eff_column_styles}[$col]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_draw"}{"eff_column_styles"}[$col]) 16 1 17
510 16 return $self->{_draw}{eff_column_styles}[$col]{$style};
511 }
512  
513 1 my $cols = $self->{columns};
514 1 my %styles;
515  
516 # apply conditional styles
517 COND:
518 1 for my $ei (0..@{ $self->{_cond_column_styles} }-1) {
519 0 my $e = $self->{_cond_column_styles}[$ei];
520 0 local $_ = $col;
521 0 my $res = $e->[0]->(
522 $self,
523 col => $col,
524 colname => $cols->[$col],
525 );
526 0 ▶ next COND unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
527 0 ▶ if (ref($res) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res eq "HASH") 0 0 0
528 0 $styles{$_} = $res->{$_} for keys %$res;
529 }
530 0 $styles{$_} = $e->[1]{$_} for keys %{ $e->[1] };
531 }
532  
533 # apply per-column styles
534 1 my $rss = $self->{_column_styles}[$col];
535 1 ▶ if ($rss) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rss) 0 1 1
536 0 $styles{$_} = $rss->{$_} for keys %$rss;
537 }
538  
539 1 $self->{_draw}{eff_column_styles}[$col] = \%styles;
540  
541 1 $styles{$style};
542 }
543  
544 0 ▶sub get_row_style {
Subroutine get_row_style: not called CC=1 SCAR=6.9
Pod documented
545 0 my ($self, $row, $style) = @_;
546  
547 0 $self->{_row_styles}[$row]{$style};
548 }
549  
550 0 ▶sub set_row_style {
Subroutine set_row_style: not called CC=4 SCAR=30.0
Pod documented
551 0 my $self = shift;
552 0 my $row = shift;
553  
554 0 ▶ my %sets = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
555  
556 0 for my $style (keys %sets) {
557 0 my $val = $sets{$style};
558 croak "Unknown per-row style '$style', please use one of [".
559 0 ▶ join(", ", @$ROW_STYLES) . "]" unless grep { $_ eq $style } @$ROW_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $style;} @$ROW_STYLES 0 0 0
560 0 $self->{_row_styles}[$row]{$style} = $val;
561 }
562 }
563  
564 0 ▶sub get_cond_row_styles {
Subroutine get_cond_row_styles: not called CC=1 SCAR=6.9
Pod documented
565 0 my $self = shift;
566 0 $self->{_cond_row_styles};
567 }
568  
569 #sub set_cond_row_style {
570 # my ($self, $styles) = @_;
571 # $self->{_cond_row_styles} = $styles;
572 #}
573  
574 0 ▶sub add_cond_row_style {
Subroutine add_cond_row_style: not called CC=5 SCAR=34.0
Pod documented
575 0 my $self = shift;
576 0 my $cond = shift;
577 0 ▶ if (ref($cond) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cond ne "CODE") 0 0 0
578 0 croak "cond must be a coderef";
579 }
580  
581 0 my $styles;
582 0 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
583 0 $styles = shift;
584 } else {
585 0 $styles = { @_ };
586 }
587  
588 0 for my $style (keys %$styles) {
589 croak "Unknown per-row style '$style', please use one of [".
590 0 ▶ join(", ", @$ROW_STYLES) . "]" unless grep { $_ eq $style } @$ROW_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $style;} @$ROW_STYLES 0 0 0
591 }
592  
593 0 push @{ $self->{_cond_row_styles} }, [$cond, $styles];
594 }
595  
596 #sub clear_cond_row_styles {
597 # my $self = shift;
598 # $self->{_cond_row_styles} = [];
599 #}
600  
601 20 ▶sub get_eff_row_style {
Subroutine get_eff_row_style: called CC=9 SCAR=29.5
Pod documented
602 20 my ($self, $row, $style) = @_;
603  
604 # the result of calculation is cached here
605 20 ▶ if (defined $self->{_draw}{eff_row_styles}[$row]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_draw"}{"eff_row_styles"}[$row]) 18 2 20
606 18 return $self->{_draw}{eff_row_styles}[$row]{$style};
607 }
608  
609 2 my $rows = $self->{rows};
610 2 my %styles;
611  
612 # apply conditional styles
613 COND:
614 2 for my $ei (0..@{ $self->{_cond_row_styles} }-1) {
615 0 my $e = $self->{_cond_row_styles}[$ei];
616 0 local $_ = $row;
617 0 my $res = $e->[0]->(
618 $self,
619 row => $row,
620 row_data => $rows->[$row],
621 );
622 0 ▶ next COND unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
623 0 ▶ if (ref($res) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res eq "HASH") 0 0 0
624 0 $styles{$_} = $res->{$_} for keys %$res;
625 }
626 0 $styles{$_} = $e->[1]{$_} for keys %{ $e->[1] };
627 }
628  
629 # apply per-row styles
630 2 my $rss = $self->{_row_styles}[$row];
631 2 ▶ if ($rss) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rss) 0 2 2
632 0 $styles{$_} = $rss->{$_} for keys %$rss;
633 }
634  
635 2 $self->{_draw}{eff_row_styles}[$row] = \%styles;
636  
637 2 $styles{$style};
638 }
639  
640 0 ▶sub get_cell_style {
Subroutine get_cell_style: not called CC=1 SCAR=6.9
Pod documented
641 0 my ($self, $row, $col, $style) = @_;
642  
643 0 $col = $self->_colnum($col);
644 0 $self->{_cell_styles}[$row][$col]{$style};
645 }
646  
647 2 ▶sub set_cell_style {
Subroutine set_cell_style: called CC=4 SCAR=14.2
Pod documented
648 2 my $self = shift;
649 2 my $row = shift;
650 2 my $col = shift;
651  
652 2 $col = $self->_colnum($col);
653  
654 0 ▶ my %sets = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 2 2
655  
656 2 for my $style (keys %sets) {
657 2 my $val = $sets{$style};
658 croak "Unknown per-cell style '$style', please use one of [".
659 2 ▶ join(", ", @$CELL_STYLES) . "]" unless grep { $_ eq $style } @$CELL_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $style;} @$CELL_STYLES 0 2 2
660 2 $self->{_cell_styles}[$row][$col]{$style} = $val;
661 }
662 }
663  
664 0 ▶sub get_cond_cell_styles {
Subroutine get_cond_cell_styles: not called CC=1 SCAR=6.9
Pod documented
665 0 my $self = shift;
666 0 $self->{_cond_cell_styles};
667 }
668  
669 #sub set_cond_cell_style {
670 # my ($self, $styles) = @_;
671 # $self->{_cond_cell_styles} = $styles;
672 #}
673  
674 0 ▶sub add_cond_cell_style {
Subroutine add_cond_cell_style: not called CC=5 SCAR=34.0
Pod documented
675 0 my $self = shift;
676 0 my $cond = shift;
677 0 ▶ if (ref($cond) ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cond ne "CODE") 0 0 0
678 0 croak "cond must be a coderef";
679 }
680  
681 0 my $styles;
682 0 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
683 0 $styles = shift;
684 } else {
685 0 $styles = { @_ };
686 }
687  
688 0 for my $style (keys %$styles) {
689 croak "Unknown per-cell style '$style', please use one of [".
690 0 ▶ join(", ", @$CELL_STYLES) . "]" unless grep { $_ eq $style } @$CELL_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $style;} @$CELL_STYLES 0 0 0
691 }
692  
693 0 push @{ $self->{_cond_cell_styles} }, [$cond, $styles];
694 }
695  
696 #sub clear_cond_cell_styles {
697 # my $self = shift;
698 # $self->{_cond_cell_styles} = [];
699 #}
700  
701 10 ▶sub get_eff_cell_style {
Subroutine get_eff_cell_style: called CC=9 SCAR=28.4
Pod documented
702 10 my ($self, $row, $col, $style) = @_;
703  
704 # the result of calculation is cached here
705 10 ▶ if (defined $self->{_draw}{eff_cell_styles}[$row][$col]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_draw"}{"eff_cell_styles"}[$row][$col]) 8 2 10
706 8 return $self->{_draw}{eff_cell_styles}[$row][$col]{$style};
707 }
708  
709 2 my $rows = $self->{rows};
710 2 my %styles;
711  
712 # apply conditional styles
713 COND:
714 2 for my $ei (0..@{ $self->{_cond_cell_styles} }-1) {
715 0 my $e = $self->{_cond_cell_styles}[$ei];
716 0 local $_ = $rows->[$row][$col];
717 0 my $res = $e->[0]->(
718 $self,
719 content => $_,
720 col => $col,
721 row => $row,
722 row_data => $rows->[$row],
723 );
724 0 ▶ next COND unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
725 0 ▶ if (ref($res) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $res eq "HASH") 0 0 0
726 0 $styles{$_} = $res->{$_} for keys %$res;
727 }
728 0 $styles{$_} = $e->[1]{$_} for keys %{ $e->[1] };
729 }
730  
731 # apply per-cell styles
732 2 my $css = $self->{_cell_styles}[$row][$col];
733 2 ▶ if ($css) {
Branch: 1 branch
BranchTrueFalseTotal
if ($css) 2 0 2
734 2 $styles{$_} = $css->{$_} for keys %$css;
735 }
736  
737 2 $self->{_draw}{eff_cell_styles}[$row][$col] = \%styles;
738  
739 2 $styles{$style};
740 }
741  
742 0 ▶sub apply_style_set {
Subroutine apply_style_set: not called CC=3 SCAR=24.8
Pod documented
743 0 my $self = shift;
744 0 my $name = shift;
745 0 ▶ $name =~ /\A[A-Za-z0-9_]+(?:::[A-Za-z0-9_]+)*\z/
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /\A[A-Za-z0-9_]+(?:::[A-Za-z0-9_]+)*\z/ or croak("Invalid style set name, please use alphanums only") 0 0 0
746 or croak "Invalid style set name, please use alphanums only";
747 {
748 0 my $name = $name;
749 0 $name =~ s!::!/!g;
750 0 require "Text/ANSITable/StyleSet/$name.pm"; ## no critic: Modules::RequireBarewordIncludes
751 }
752 0 ▶ my %args = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
753 0 my $obj = "Text::ANSITable::StyleSet::$name"->new(%args);
754 0 $obj->apply($self);
755 }
756  
757 0 ▶sub list_border_styles {
Subroutine list_border_styles: not called CC=2 SCAR=17.9
Pod documented
758 0 require Module::List;
759 0 my ($self) = @_;
760  
761 0 my $mods = Module::List::list_modules(
762 "BorderStyle::", {list_modules=>1, recurse=>1});
763 0 my @res;
764 0 for (sort keys %$mods) {
765 0 s/\ABorderStyle:://;
766 0 push @res, $_;
767 }
768 0 @res;
769 }
770  
771 0 ▶sub list_color_themes {
Subroutine list_color_themes: not called CC=2 SCAR=17.9
Pod documented
772 0 require Module::List;
773 0 my ($self) = @_;
774  
775 0 my $mods = Module::List::list_modules(
776 "ColorTheme::", {list_modules=>1, recurse=>1});
777 0 my @res;
778 0 for (sort keys %$mods) {
779 0 s/\AColorTheme:://;
780 0 push @res, $_;
781 }
782 0 @res;
783 }
784  
785 0 ▶sub list_style_sets {
Subroutine list_style_sets: not called CC=6 SCAR=37.4
Pod documented
786 0 require Module::List;
787 0 require Module::Load;
788 0 require Package::MoreUtil;
789  
790 0 my ($self, $detail) = @_;
791  
792 0 ▶ my $prefix = (ref($self) ? ref($self) : $self ) .
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
793 '::StyleSet'; # XXX allow override
794 0 my $all_sets = $self->{_all_style_sets};
795  
796 0 ▶ if (!$all_sets) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($all_sets) 0 0 0
797 0 my $mods = Module::List::list_modules("$prefix\::",
798 {list_modules=>1, recurse=>1});
799 0 $all_sets = {};
800 0 for my $mod (sort keys %$mods) {
801 #$log->tracef("Loading style set module '%s' ...", $mod);
802 0 Module::Load::load($mod);
803 0 my $name = $mod; $name =~ s/\A\Q$prefix\:://;
804 0 my $summary = $mod->summary;
805 # we don't have meta, so dig it ourselves
806 0 my %ct = Package::MoreUtil::list_package_contents($mod);
807 0 ▶ my $args = [sort grep {!/\W/ && !/\A(new|summary|apply)\z/}
Condition0%0/3
/\W/ || /\A(new|summary|apply)\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
/\W/ || /\A(new|summary|apply)\z/
/\W/ /\A(new|summary|apply)\z/
Truth table0%0/3
A || B
A= /\W/B= /\A(new|summary|apply)\z/
ABresult
1X1
011
000
808 keys %ct];
809 0 $all_sets->{$name} = {name=>$name, summary=>$summary, args=>$args};
810 }
811 0 $self->{_all_style_sets} = $all_sets;
812 }
813  
814 0 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) { } 0 0 0
815 0 return $all_sets;
816 } else {
817 0 return (sort keys %$all_sets);
818 }
819 }
820  
821 # read environment variables for style, this will only be done once per object
822 1 ▶sub _read_style_envs {
Subroutine _read_style_envs: called CC=21 SCAR=57.5
823 1 my $self = shift;
824  
825 1 ▶ return if $self->{_read_style_envs}++;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_read_style_envs"}++ 0 1 1
826  
827 1 ▶ if ($ENV{ANSITABLE_COLUMN_STYLES}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ANSITABLE_COLUMN_STYLES"}) 0 1 1
828 0 require JSON::MaybeXS;
829 0 my $ss = JSON::MaybeXS::decode_json($ENV{ANSITABLE_COLUMN_STYLES});
830 0 ▶ croak "ANSITABLE_COLUMN_STYLES must be a hash"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ss eq "HASH" 0 0 0
831 unless ref($ss) eq 'HASH';
832 0 for my $col (keys %$ss) {
833 0 my $ci = $self->_colnum($col);
834 0 my $s = $ss->{$col};
835 0 for my $k (keys %$s) {
836 0 my $v = $s->{$k};
837 croak "Unknown column style '$k' (for column $col) in ".
838 "ANSITABLE_COLUMN_STYLES environment, ".
839 "please use one of [".join(", ", @$COLUMN_STYLES)."]"
840 0 ▶ unless grep { $_ eq $k } @$COLUMN_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $k;} @$COLUMN_STYLES 0 0 0
841 0 ▶ $self->{_column_styles}[$ci]{$k} //= $v;
Condition0%0/3
$self->{"_column_styles"}[$ci]{$k} //= $v
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_column_styles"}[$ci]{$k} //= $v
$self->{"_column_styles"}[$ci]{$k} $v
Truth table0%0/3
A //= B
A= $self->{"_column_styles"}[$ci]{$k}B= $v
ABresult
1X1
011
000
842 }
843 }
844 }
845  
846 1 ▶ if ($ENV{ANSITABLE_ROW_STYLES}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ANSITABLE_ROW_STYLES"}) 0 1 1
847 0 require JSON::MaybeXS;
848 0 my $ss = JSON::MaybeXS::decode_json($ENV{ANSITABLE_ROW_STYLES});
849 0 ▶ croak "ANSITABLE_ROW_STYLES must be a hash"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ss eq "HASH" 0 0 0
850 unless ref($ss) eq 'HASH';
851 0 for my $row (keys %$ss) {
852 0 my $s = $ss->{$row};
853 0 for my $k (keys %$s) {
854 0 my $v = $s->{$k};
855 croak "Unknown row style '$k' (for row $row) in ".
856 "ANSITABLE_ROW_STYLES environment, ".
857 "please use one of [".join(", ", @$ROW_STYLES)."]"
858 0 ▶ unless grep { $_ eq $k } @$ROW_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $k;} @$ROW_STYLES 0 0 0
859 0 ▶ $self->{_row_styles}[$row]{$k} //= $v;
Condition0%0/3
$self->{"_row_styles"}[$row]{$k} //= $v
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_row_styles"}[$row]{$k} //= $v
$self->{"_row_styles"}[$row]{$k} $v
Truth table0%0/3
A //= B
A= $self->{"_row_styles"}[$row]{$k}B= $v
ABresult
1X1
011
000
860 }
861 }
862 }
863  
864 1 ▶ if ($ENV{ANSITABLE_CELL_STYLES}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ANSITABLE_CELL_STYLES"}) 0 1 1
865 0 require JSON::MaybeXS;
866 0 my $ss = JSON::MaybeXS::decode_json($ENV{ANSITABLE_CELL_STYLES});
867 0 ▶ croak "ANSITABLE_CELL_STYLES must be a hash"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ss eq "HASH" 0 0 0
868 unless ref($ss) eq 'HASH';
869 0 for my $cell (keys %$ss) {
870 0 ▶ croak "Invalid cell specification in ANSITABLE_CELL_STYLES: ".
Branch: 1 branch
BranchTrueFalseTotal
unless $cell =~ /^(.+),(.+)$/ 0 0 0
871 "$cell, please use 'row,col'"
872 unless $cell =~ /^(.+),(.+)$/;
873 0 my $row = $1;
874 0 my $col = $2;
875 0 my $ci = $self->_colnum($col);
876 0 my $s = $ss->{$cell};
877 0 for my $k (keys %$s) {
878 0 my $v = $s->{$k};
879 croak "Unknown cell style '$k' (for cell $row,$col) in ".
880 "ANSITABLE_CELL_STYLES environment, ".
881 "please use one of [".join(", ", @$CELL_STYLES)."]"
882 0 ▶ unless grep { $_ eq $k } @$CELL_STYLES;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $k;} @$CELL_STYLES 0 0 0
883 0 ▶ $self->{_cell_styles}[$row][$ci]{$k} //= $v;
Condition0%0/3
$self->{"_cell_styles"}[$row][$ci]{$k} //= $v
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_cell_styles"}[$row][$ci]{$k} //= $v
$self->{"_cell_styles"}[$row][$ci]{$k} $v
Truth table0%0/3
A //= B
A= $self->{"_cell_styles"}[$row][$ci]{$k}B= $v
ABresult
1X1
011
000
884 }
885 }
886 }
887 }
888  
889 # determine which columns to show (due to column_filter)
890 1 ▶sub _calc_fcols {
Subroutine _calc_fcols: called CC=4 SCAR=17.9
891 1 my $self = shift;
892  
893 1 my $cols = $self->{columns};
894 1 my $cf = $self->{column_filter};
895  
896 1 my $fcols;
897 1 ▶ if (ref($cf) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $cf eq 'CODE') { } 0 1 1
elsif (ref $cf eq 'ARRAY') { } 0 1 1
898 0 $fcols = [grep {$cf->($_)} @$cols];
899 } elsif (ref($cf) eq 'ARRAY') {
900 0 ▶ $fcols = [grep {defined} map {looks_like_number($_) ?
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($_) ? : 0 0 0
901 $cols->[$_] : $_} @$cf];
902 } else {
903 1 $fcols = $cols;
904 }
905 1 $self->{_draw}{fcols} = $fcols;
906 }
907  
908 # calculate widths/heights of header, store width settings, column [lr]pads
909 1 ▶sub _calc_header_height {
Subroutine _calc_header_height: called CC=13 SCAR=29.4
910 1 my $self = shift;
911  
912 1 my $cols = $self->{columns};
913 1 my $fcols = $self->{_draw}{fcols};
914  
915 1 my $fcol_widths = []; # index = [colnum]
916 1 my $header_height = 1;
917 1 my $fcol_lpads = []; # index = [colnum]
918 1 my $fcol_rpads = []; # ditto
919 1 my $fcol_setwidths = []; # index = [colnum], from cell_width/col width
920 1 my $frow_setheights = []; # index = [frownum], from cell_height/row height
921  
922 1 my %seen;
923 1 ▶ my $lpad = $self->{cell_lpad} // $self->{cell_pad}; # tbl-lvl leftp
Condition33%1/3
$self->{"cell_lpad"} // $self->{"cell_pad"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"cell_lpad"} // $self->{"cell_pad"}
$self->{"cell_lpad"} $self->{"cell_pad"}
Truth table33%1/3
A // B
A= $self->{"cell_lpad"}B= $self->{"cell_pad"}
ABresult
1X1
011
000
924 1 ▶ my $rpad = $self->{cell_rpad} // $self->{cell_pad}; # tbl-lvl rightp
Condition33%1/3
$self->{"cell_rpad"} // $self->{"cell_pad"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"cell_rpad"} // $self->{"cell_pad"}
$self->{"cell_rpad"} $self->{"cell_pad"}
Truth table33%1/3
A // B
A= $self->{"cell_rpad"}B= $self->{"cell_pad"}
ABresult
1X1
011
000
925 1 for my $i (0..@$cols-1) {
926 1 ▶ next unless grep { $_ eq $cols->[$i] } @$fcols;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $cols->[$i];} @$fcols 0 1 1
927 1 ▶ next if $seen{$cols->[$i]}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$cols->[$i]}++ 0 1 1
928  
929 $fcol_setwidths->[$i] = $self->get_eff_column_style($i, 'width') //
930 1 ▶ $self->{cell_width};
Condition33%1/3
$self->get_eff_column_style($i, "width") // $self->{"cell_width"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->get_eff_column_style($i, "width") // $self->{"cell_width"}
$self->get_eff_column_style($i, "width") $self->{"cell_width"}
Truth table33%1/3
A // B
A= $self->get_eff_column_style($i, "width")B= $self->{"cell_width"}
ABresult
1X1
011
000
931 1 my $wh = $self->_opt_calc_cell_width_height(undef, $i, $cols->[$i]);
932 1 $fcol_widths->[$i] = $wh->[0];
933 1 ▶ $header_height = $wh->[1]
Branch: 1 branch
BranchTrueFalseTotal
if not defined $header_height or $header_height < $wh->[1] 0 1 1
Condition33%1/3
not defined $header_height or $header_height < $wh->[1]
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $header_height or $header_height < $wh->[1]
not defined $header_height $header_height < $wh->[1]
Truth table33%1/3
not(A) or B
A= not defined $header_heightB= $header_height < $wh->[1]
ABresult
1X1
011
000
934 if !defined($header_height) || $header_height < $wh->[1];
935 1 ▶ $fcol_lpads->[$i] = $self->get_eff_column_style($i, 'lpad') //
Condition33%2/6
($self->get_eff_column_style($i, "lpad") // $self->get_eff_column_style($i, "pad")) // $lpad
l!l&&r!l&&!r
010
$self->get_eff_column_style($i, "lpad") // $self->get_eff_column_style($i, "pad")
l!l&&r!l&&!r
001
MC/DC0%0/3
($self->get_eff_column_style($i, "lpad") // $self->get_eff_column_style($i, "pad")) // $lpad
$self->get_eff_column_style($i, "lpad") $self->get_eff_column_style($i, "pad") $lpad
Truth table25%1/4
A // B // C
A= $self->get_eff_column_style($i, "lpad")B= $self->get_eff_column_style($i, "pad")C= $lpad
ABCresult
1XX1
01X1
0011
0000
936 $self->get_eff_column_style($i, 'pad') // $lpad;
937 1 ▶ $fcol_rpads->[$i] = $self->get_eff_column_style($i, 'rpad') //
Condition33%2/6
($self->get_eff_column_style($i, "rpad") // $self->get_eff_column_style($i, "pad")) // $rpad
l!l&&r!l&&!r
010
$self->get_eff_column_style($i, "rpad") // $self->get_eff_column_style($i, "pad")
l!l&&r!l&&!r
001
MC/DC0%0/3
($self->get_eff_column_style($i, "rpad") // $self->get_eff_column_style($i, "pad")) // $rpad
$self->get_eff_column_style($i, "rpad") $self->get_eff_column_style($i, "pad") $rpad
Truth table25%1/4
A // B // C
A= $self->get_eff_column_style($i, "rpad")B= $self->get_eff_column_style($i, "pad")C= $rpad
ABCresult
1XX1
01X1
0011
0000
938 $self->get_eff_column_style($i, 'pad') // $rpad;
939 }
940  
941 1 $self->{_draw}{header_height} = $header_height;
942 1 $self->{_draw}{fcol_lpads} = $fcol_lpads;
943 1 $self->{_draw}{fcol_rpads} = $fcol_rpads;
944 1 $self->{_draw}{fcol_setwidths} = $fcol_setwidths;
945 1 $self->{_draw}{frow_setheights} = $frow_setheights;
946 1 $self->{_draw}{fcol_widths} = $fcol_widths;
947 }
948  
949 # determine which rows to show, calculate vertical paddings of data rows, store
950 # height settings
951 1 ▶sub _calc_frows {
Subroutine _calc_frows: called CC=14 SCAR=32.5
952 1 my $self = shift;
953  
954 1 my $rows = $self->{rows};
955 1 my $rf = $self->{row_filter};
956 1 my $frow_setheights = $self->{_draw}{frow_setheights};
957  
958 1 my $frow_tpads = []; # index = [frownum]
959 1 my $frow_bpads = []; # ditto
960 1 my $frows = [];
961 1 my $frow_separators = [];
962 1 my $frow_orig_indices = []; # needed when accessing original row data
963  
964 1 ▶ my $tpad = $self->{cell_tpad} // $self->{cell_vpad}; # tbl-lvl top pad
Condition33%1/3
$self->{"cell_tpad"} // $self->{"cell_vpad"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"cell_tpad"} // $self->{"cell_vpad"}
$self->{"cell_tpad"} $self->{"cell_vpad"}
Truth table33%1/3
A // B
A= $self->{"cell_tpad"}B= $self->{"cell_vpad"}
ABresult
1X1
011
000
965 1 ▶ my $bpad = $self->{cell_bpad} // $self->{cell_vpad}; # tbl-lvl botom pad
Condition33%1/3
$self->{"cell_bpad"} // $self->{"cell_vpad"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"cell_bpad"} // $self->{"cell_vpad"}
$self->{"cell_bpad"} $self->{"cell_vpad"}
Truth table33%1/3
A // B
A= $self->{"cell_bpad"}B= $self->{"cell_vpad"}
ABresult
1X1
011
000
966 1 my $i = -1;
967 1 my $j = -1;
968 1 for my $row (@$rows) {
969 2 $i++;
970 2 ▶ if (ref($rf) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $rf eq 'CODE') { } 0 2 2
elsif ($rf) { } 0 2 2
971 0 ▶ next unless $rf->($row, $i);
Branch: 1 branch
BranchTrueFalseTotal
unless &$rf($row, $i) 0 0 0
972 } elsif ($rf) {
973 0 ▶ next unless grep { $_ == $i } @$rf;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ == $i;} @$rf 0 0 0
974 }
975 2 $j++;
976 push @$frow_setheights, $self->get_eff_row_style($i, 'height') //
977 2 ▶ $self->{cell_height};
Condition33%1/3
$self->get_eff_row_style($i, "height") // $self->{"cell_height"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->get_eff_row_style($i, "height") // $self->{"cell_height"}
$self->get_eff_row_style($i, "height") $self->{"cell_height"}
Truth table33%1/3
A // B
A= $self->get_eff_row_style($i, "height")B= $self->{"cell_height"}
ABresult
1X1
011
000
978 2 push @$frows, [@$row]; # 1-level clone, for storing formatted values
979 0 ▶ push @$frow_separators, $j if grep { $_ == $i } @{ $self->{_row_separators} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == $i;} @{$$self{"_row_separators"};} 0 2 2
980 2 ▶ push @$frow_tpads, $self->get_eff_row_style($i, 'tpad') //
Condition33%2/6
($self->get_eff_row_style($i, "tpad") // $self->get_eff_row_style($i, "vpad")) // $tpad
l!l&&r!l&&!r
020
$self->get_eff_row_style($i, "tpad") // $self->get_eff_row_style($i, "vpad")
l!l&&r!l&&!r
002
MC/DC0%0/3
($self->get_eff_row_style($i, "tpad") // $self->get_eff_row_style($i, "vpad")) // $tpad
$self->get_eff_row_style($i, "tpad") $self->get_eff_row_style($i, "vpad") $tpad
Truth table25%1/4
A // B // C
A= $self->get_eff_row_style($i, "tpad")B= $self->get_eff_row_style($i, "vpad")C= $tpad
ABCresult
1XX1
01X1
0011
0000
981 $self->get_eff_row_style($i, 'vpad') // $tpad;
982 2 ▶ push @$frow_bpads, $self->get_eff_row_style($i, 'bpad') //
Condition33%2/6
($self->get_eff_row_style($i, "bpad") // $self->get_eff_row_style($i, "vpad")) // $bpad
l!l&&r!l&&!r
020
$self->get_eff_row_style($i, "bpad") // $self->get_eff_row_style($i, "vpad")
l!l&&r!l&&!r
002
MC/DC0%0/3
($self->get_eff_row_style($i, "bpad") // $self->get_eff_row_style($i, "vpad")) // $bpad
$self->get_eff_row_style($i, "bpad") $self->get_eff_row_style($i, "vpad") $bpad
Truth table25%1/4
A // B // C
A= $self->get_eff_row_style($i, "bpad")B= $self->get_eff_row_style($i, "vpad")C= $bpad
ABCresult
1XX1
01X1
0011
0000
983 $self->get_eff_row_style($i, 'vpad') // $bpad;
984 2 push @$frow_orig_indices, $i;
985 }
986  
987 1 $self->{_draw}{frows} = $frows;
988 1 $self->{_draw}{frow_separators} = $frow_separators;
989 1 $self->{_draw}{frow_tpads} = $frow_tpads;
990 1 $self->{_draw}{frow_bpads} = $frow_bpads;
991 1 $self->{_draw}{frow_orig_indices} = $frow_orig_indices;
992 }
993  
994 # detect column type from data/header name. assign default column align, valign,
995 # fgcolor, bgcolor, formats.
996 1 ▶sub _detect_column_types {
Subroutine _detect_column_types: called CC=19 SCAR=38.9
997 1 my $self = shift;
998  
999 1 my $cols = $self->{columns};
1000 1 my $rows = $self->{rows};
1001  
1002 1 my $fcol_detect = [];
1003 1 my %seen;
1004 1 for my $i (0..@$cols-1) {
1005 1 my $col = $cols->[$i];
1006 1 my $res = {};
1007 1 $fcol_detect->[$i] = $res;
1008  
1009 # optim: skip detecting columns we're not showing
1010 1 ▶ next unless grep { $_ eq $col } @{ $self->{_draw}{fcols} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $col;} @{$$self{"_draw"}{"fcols"};} 0 1 1
1011  
1012 # but detect from all rows, not just ones we're showing
1013 1 my $type = $self->get_eff_column_style($col, 'type');
1014 1 my $subtype;
1015 DETECT:
1016 {
1017 1 ▶ last DETECT if $type;
Branch: 1 branch
BranchTrueFalseTotal
if $type 0 1 1
1018 1 ▶ if ($col =~ /^(can|is|has|does)_|\?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col =~ /^(can|is|has|does)_|\?$/) 0 1 1
1019 0 $type = 'bool';
1020 0 last DETECT;
1021 }
1022  
1023 1 require Parse::VarName;
1024 1 my @words = map {lc} @{ Parse::VarName::split_varname_words(
1025 varname=>$col) };
1026 1 for my $w (qw/date time ctime mtime utime atime stime/) {
1027 7 ▶ if (grep { $_ eq $w } @words) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $w;} @words) 0 7 7
1028 0 $type = 'date';
1029 0 last DETECT;
1030 }
1031 }
1032  
1033 1 my $pass = 1;
1034 1 for my $j (0..@$rows) {
1035 1 my $v = $rows->[$j][$i];
1036 1 ▶ next unless defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 1 1
1037 1 ▶ do { $pass=0; last } unless looks_like_number($v);
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($v)) 1 0 1
1038 }
1039 1 ▶ if ($pass) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass) 0 1 1
1040 0 $type = 'num';
1041 0 ▶ if ($col =~ /(pct|percent(?:age))\b|\%/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col =~ /(pct|percent(?:age))\b|\%/) 0 0 0
1042 0 $subtype = 'pct';
1043 }
1044 0 last DETECT;
1045 }
1046 1 $type = 'str';
1047 } # DETECT
1048  
1049 1 $res->{type} = $type;
1050 1 ▶ if ($type eq 'bool') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'bool') { } 0 1 1
elsif ($type eq 'date') { } 0 1 1
elsif ($type =~ /\A(num|float|int)\z/) { } 0 1 1
1051 0 $res->{align} = 'center';
1052 0 $res->{valign} = 'center';
1053 0 $res->{fgcolor} = $self->{color_theme_obj}->get_item_color('bool_data');
1054 $res->{formats} = [[bool => {style => $self->{use_utf8} ?
1055 0 ▶ "check_cross" : "Y_N"}]];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'use_utf8'} ? : 0 0 0
1056 } elsif ($type eq 'date') {
1057 0 $res->{align} = 'middle';
1058 0 $res->{fgcolor} = $self->{color_theme_obj}->get_item_color('date_data');
1059 0 $res->{formats} = [['date' => {}]];
1060 } elsif ($type =~ /\A(num|float|int)\z/) {
1061 0 $res->{align} = 'right';
1062 0 $res->{fgcolor} = $self->{color_theme_obj}->get_item_color('num_data');
1063 0 ▶ if (($subtype//"") eq 'pct') {
Branch: 1 branch
BranchTrueFalseTotal
if (($subtype // "") eq "pct") 0 0 0
Condition0%0/2
$subtype // ""
l!l
00
MC/DC0%0/1
$subtype // ""
$subtype
Truth table0%0/2
A
A= $subtype
Aresult
11
00
1064 0 $res->{formats} = [[num => {style=>'percent'}]];
1065 }
1066 } else {
1067 1 $res->{fgcolor} = $self->{color_theme_obj}->get_item_color('str_data');
1068 1 ▶ $res->{wrap} = $ENV{WRAP} // 1;
Condition50%1/2
$ENV{"WRAP"} // 1
l!l
01
MC/DC0%0/1
$ENV{"WRAP"} // 1
$ENV{"WRAP"}
Truth table50%1/2
A
A= $ENV{"WRAP"}
Aresult
11
00
1069 }
1070 }
1071  
1072 #use Data::Dump; print "D:fcol_detect: "; dd $fcol_detect;
1073 1 $self->{_draw}{fcol_detect} = $fcol_detect;
1074 }
1075  
1076 # calculate width and height of a cell, but skip calculating (to save some
1077 # cycles) if width is already set by frow_setheights / fcol_setwidths.
1078 3 ▶sub _opt_calc_cell_width_height {
Subroutine _opt_calc_cell_width_height: called CC=17 SCAR=42.5
1079 3 my ($self, $frownum, $col, $text) = @_;
1080  
1081 3 $col = $self->_colnum($col);
1082 3 my $setw = $self->{_draw}{fcol_setwidths}[$col];
1083 3 ▶ my $calcw = !defined($setw) || $setw < 0;
Condition33%1/3
!defined($setw) || $setw < 0
l!l&&r!l&&!r
300
MC/DC0%0/2
!defined($setw) || $setw < 0
!defined($setw) $setw < 0
Truth table33%1/3
not(A) || B
A= !defined($setw)B= $setw < 0
ABresult
1X1
011
000
1084 my $seth = defined($frownum) ?
1085 3 ▶ $self->{_draw}{frow_setheights}[$frownum] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $frownum ? : 2 1 3
1086 3 ▶ my $calch = !defined($seth) || $seth < 0;
Condition33%1/3
!defined($seth) || $seth < 0
l!l&&r!l&&!r
300
MC/DC0%0/2
!defined($seth) || $seth < 0
!defined($seth) $seth < 0
Truth table33%1/3
not(A) || B
A= !defined($seth)B= $seth < 0
ABresult
1X1
011
000
1087  
1088 3 my $wh;
1089 3 ▶ if ($calcw) {
Branch: 2 branches
BranchTrueFalseTotal
if ($calcw) { } 3 0 3
elsif ($calch) { } 0 0 0
1090 3 $wh = $self->{_func_length_height}->($text);
1091 3 ▶ $wh->[0] = -$setw if defined($setw) && $setw<0 && $wh->[0] < -$setw;
Branch: 1 branch
BranchTrueFalseTotal
if defined $setw and $setw < 0 and $wh->[0] < -$setw 0 3 3
Condition33%2/6
defined $setw and $setw < 0 and $wh->[0] < -$setw
!ll&&!rl&&r
300
defined $setw and $setw < 0
!ll&&!rl&&r
300
MC/DC0%0/3
defined $setw and $setw < 0 and $wh->[0] < -$setw
defined $setw $setw < 0 $wh->[0] < -$setw
Truth table25%1/4
A and B and C
A= defined $setwB= $setw < 0C= $wh->[0] < -$setw
ABCresult
0XX0
10X0
1100
1111
1092 3 ▶ $wh->[1] = $seth if !$calch;
Branch: 1 branch
BranchTrueFalseTotal
unless $calch 0 3 3
1093 3 ▶ $wh->[1] = -$seth if defined($seth) && $seth<0 && $wh->[1] < -$seth;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seth and $seth < 0 and $wh->[1] < -$seth 0 3 3
Condition33%2/6
defined $seth and $seth < 0 and $wh->[1] < -$seth
!ll&&!rl&&r
300
defined $seth and $seth < 0
!ll&&!rl&&r
300
MC/DC0%0/3
defined $seth and $seth < 0 and $wh->[1] < -$seth
defined $seth $seth < 0 $wh->[1] < -$seth
Truth table25%1/4
A and B and C
A= defined $sethB= $seth < 0C= $wh->[1] < -$seth
ABCresult
0XX0
10X0
1100
1111
1094 } elsif ($calch) {
1095 0 ▶ my $h = 1; $h++ while $text =~ /\n/go;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /\n/go and do { ++$h } 0 0 0
1096 0 ▶ $h = -$seth if defined($seth) && $seth<0 && $h < -$seth;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seth and $seth < 0 and $h < -$seth 0 0 0
Condition0%0/6
defined $seth and $seth < 0 and $h < -$seth
!ll&&!rl&&r
000
defined $seth and $seth < 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $seth and $seth < 0 and $h < -$seth
defined $seth $seth < 0 $h < -$seth
Truth table0%0/4
A and B and C
A= defined $sethB= $seth < 0C= $h < -$seth
ABCresult
0XX0
10X0
1100
1111
1097 0 $wh = [$setw, $h];
1098 } else {
1099 0 $wh = [$setw, $seth];
1100 }
1101 #say "D:_opt_calc_cell_width_height(", $frownum//"undef", ", $col) = $wh->[0], $wh->[1]";
1102 3 $wh;
1103 }
1104  
1105 1 ▶sub _apply_column_formats {
Subroutine _apply_column_formats: called CC=12 SCAR=32.6
1106 1 my $self = shift;
1107  
1108 1 my $cols = $self->{columns};
1109 1 my $frows = $self->{_draw}{frows};
1110 1 my $fcols = $self->{_draw}{fcols};
1111 1 my $fcol_detect = $self->{_draw}{fcol_detect};
1112  
1113 1 my %seen;
1114 1 for my $i (0..@$cols-1) {
1115 1 ▶ next unless grep { $_ eq $cols->[$i] } @$fcols;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $cols->[$i];} @$fcols 0 1 1
1116 1 ▶ next if $seen{$cols->[$i]}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$cols->[$i]}++ 0 1 1
1117 1 my @fmts = @{ $self->get_eff_column_style($i, 'formats') //
1118 1 ▶ $fcol_detect->[$i]{formats} // [] };
Condition40%2/5
($self->get_eff_column_style($i, "formats") // $fcol_detect->[$i]{"formats"}) // []
l!l
01
$self->get_eff_column_style($i, "formats") // $fcol_detect->[$i]{"formats"}
l!l&&r!l&&!r
001
MC/DC0%0/2
($self->get_eff_column_style($i, "formats") // $fcol_detect->[$i]{"formats"}) // []
$self->get_eff_column_style($i, "formats") $fcol_detect->[$i]{"formats"}
Truth table33%1/3
A // B
A= $self->get_eff_column_style($i, "formats")B= $fcol_detect->[$i]{"formats"}
ABresult
1X1
011
000
1119 1 ▶ if (@fmts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fmts) { } 0 1 1
1120 0 require Data::Unixish::Apply;
1121 my $res = Data::Unixish::Apply::apply(
1122 0 in => [map {$frows->[$_][$i]} 0..@$frows-1],
1123 functions => \@fmts,
1124 );
1125 0 ▶ croak "Can't format column $cols->[$i]: $res->[0] - $res->[1]"
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
1126 unless $res->[0] == 200;
1127 0 $res = $res->[2];
1128 0 ▶ for (0..@$frows-1) { $frows->[$_][$i] = $res->[$_] // "" }
Condition0%0/2
$res->[$_] // ""
l!l
00
MC/DC0%0/1
$res->[$_] // ""
$res->[$_]
Truth table0%0/2
A
A= $res->[$_]
Aresult
11
00
1129 } else {
1130 # change null to ''
1131 1 ▶ for (0..@$frows-1) { $frows->[$_][$i] //= "" }
Condition50%1/2
$frows->[$_][$i] //= ""
l!l
20
MC/DC0%0/1
$frows->[$_][$i] //= ""
$frows->[$_][$i]
Truth table50%1/2
A
A= $frows->[$_][$i]
Aresult
11
00
1132 }
1133 }
1134 }
1135  
1136 1 ▶sub _apply_cell_formats {
Subroutine _apply_cell_formats: called CC=8 SCAR=21.2
1137 1 my $self = shift;
1138  
1139 1 my $cols = $self->{columns};
1140 1 my $rows = $self->{rows};
1141 1 my $fcols = $self->{_draw}{fcols};
1142 1 my $frows = $self->{_draw}{frows};
1143 1 my $frow_orig_indices = $self->{_draw}{frow_orig_indices};
1144  
1145 1 for my $i (0..@$frows-1) {
1146 2 my %seen;
1147 2 my $origi = $frow_orig_indices->[$i];
1148 2 for my $j (0..@$cols-1) {
1149 2 ▶ next unless grep { $_ eq $cols->[$j] } @$fcols;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $cols->[$j];} @$fcols 0 2 2
1150 2 ▶ next if $seen{$cols->[$j]}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$cols->[$j]}++ 0 2 2
1151  
1152 2 my $fmts = $self->get_eff_cell_style($origi, $j, 'formats');
1153 2 ▶ if (defined $fmts) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fmts) 2 0 2
1154 2 require Data::Unixish::Apply;
1155 2 my $res = Data::Unixish::Apply::apply(
1156 in => [ $frows->[$i][$j] ],
1157 functions => $fmts,
1158 );
1159 2 ▶ croak "Can't format cell ($origi, $cols->[$j]): ".
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 2 2
1160 "$res->[0] - $res->[1]" unless $res->[0] == 200;
1161 2 ▶ $frows->[$i][$j] = $res->[2][0] // "";
Condition50%1/2
$res->[2][0] // ""
l!l
20
MC/DC0%0/1
$res->[2][0] // ""
$res->[2][0]
Truth table50%1/2
A
A= $res->[2][0]
Aresult
11
00
1162 }
1163 } # col
1164 }
1165 }
1166  
1167 1 ▶sub _calc_row_widths_heights {
Subroutine _calc_row_widths_heights: called CC=10 SCAR=24.4
1168 1 my $self = shift;
1169  
1170 1 my $cols = $self->{columns};
1171 1 my $fcols = $self->{_draw}{fcols};
1172 1 my $frows = $self->{_draw}{frows};
1173  
1174 1 my $frow_heights = [];
1175 1 my $fcol_widths = $self->{_draw}{fcol_widths};
1176 1 my $frow_orig_indices = $self->{_draw}{frow_orig_indices};
1177  
1178 1 my $height = $self->{cell_height};
1179 1 ▶ my $tpad = $self->{cell_tpad} // $self->{cell_vpad}; # tbl-lvl tpad
Condition33%1/3
$self->{"cell_tpad"} // $self->{"cell_vpad"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"cell_tpad"} // $self->{"cell_vpad"}
$self->{"cell_tpad"} $self->{"cell_vpad"}
Truth table33%1/3
A // B
A= $self->{"cell_tpad"}B= $self->{"cell_vpad"}
ABresult
1X1
011
000
1180 1 ▶ my $bpad = $self->{cell_bpad} // $self->{cell_vpad}; # tbl-lvl bpad
Condition33%1/3
$self->{"cell_bpad"} // $self->{"cell_vpad"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"cell_bpad"} // $self->{"cell_vpad"}
$self->{"cell_bpad"} $self->{"cell_vpad"}
Truth table33%1/3
A // B
A= $self->{"cell_bpad"}B= $self->{"cell_vpad"}
ABresult
1X1
011
000
1181 1 my $cswidths = [map {$self->get_eff_column_style($_, 'width')} 0..@$cols-1];
1182 1 for my $i (0..@$frows-1) {
1183 2 my %seen;
1184 2 my $origi = $frow_orig_indices->[$i];
1185 2 my $rsheight = $self->get_eff_row_style($origi, 'height');
1186 2 for my $j (0..@$cols-1) {
1187 2 ▶ next unless grep { $_ eq $cols->[$j] } @$fcols;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $cols->[$j];} @$fcols 0 2 2
1188 2 ▶ next if $seen{$cols->[$j]}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$cols->[$j]}++ 0 2 2
1189  
1190 2 my $wh = $self->_opt_calc_cell_width_height($i,$j,$frows->[$i][$j]);
1191  
1192 2 ▶ $fcol_widths->[$j] = $wh->[0] if $fcol_widths->[$j] < $wh->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $fcol_widths->[$j] < $wh->[0] 0 2 2
1193 2 ▶ $frow_heights->[$i] = $wh->[1] if !defined($frow_heights->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if not defined $frow_heights->[$i] or $frow_heights->[$i] < $wh->[1] 2 0 2
Condition33%1/3
not defined $frow_heights->[$i] or $frow_heights->[$i] < $wh->[1]
l!l&&r!l&&!r
200
MC/DC0%0/2
not defined $frow_heights->[$i] or $frow_heights->[$i] < $wh->[1]
not defined $frow_heights->[$i] $frow_heights->[$i] < $wh->[1]
Truth table33%1/3
not(A) or B
A= not defined $frow_heights->[$i]B= $frow_heights->[$i] < $wh->[1]
ABresult
1X1
011
000
1194 || $frow_heights->[$i] < $wh->[1];
1195 } # col
1196 }
1197 1 $self->{_draw}{frow_heights} = $frow_heights;
1198 }
1199  
1200 1 ▶sub _wrap_wrappable_columns {
Subroutine _wrap_wrappable_columns: called CC=10 SCAR=28.2
1201 1 my $self = shift;
1202  
1203 1 my $cols = $self->{columns};
1204 1 my $fcols = $self->{_draw}{fcols};
1205 1 my $frows = $self->{_draw}{frows};
1206 1 my $fcol_detect = $self->{_draw}{fcol_detect};
1207 1 my $fcol_setwidths = $self->{_draw}{fcol_setwidths};
1208  
1209 1 my %seen;
1210 1 for my $i (0..@$cols-1) {
1211 1 ▶ next unless grep { $_ eq $cols->[$i] } @$fcols;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $cols->[$i];} @$fcols 0 1 1
1212 1 ▶ next if $seen{$cols->[$i]}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$cols->[$i]}++ 0 1 1
1213  
1214 1 ▶ if (($self->get_eff_column_style($i, 'wrap') // $self->{column_wrap} //
Branch: 1 branch
BranchTrueFalseTotal
if (($self->get_eff_column_style($i, "wrap") // $self->{"column_wrap"}) // $fcol_detect->[$i]{"wrap"} and defined $fcol_setwidths->[$i] and $fcol_setwidths->[$i] > 0) 0 1 1
Condition33%4/12
($self->get_eff_column_style($i, "wrap") // $self->{"column_wrap"}) // $fcol_detect->[$i]{"wrap"} and defined $fcol_setwidths->[$i] and $fcol_setwidths->[$i] > 0
!ll&&!rl&&r
100
($self->get_eff_column_style($i, "wrap") // $self->{"column_wrap"}) // $fcol_detect->[$i]{"wrap"} and defined $fcol_setwidths->[$i]
!ll&&!rl&&r
010
($self->get_eff_column_style($i, "wrap") // $self->{"column_wrap"}) // $fcol_detect->[$i]{"wrap"}
l!l&&r!l&&!r
010
$self->get_eff_column_style($i, "wrap") // $self->{"column_wrap"}
l!l&&r!l&&!r
001
MC/DC0%0/5
($self->get_eff_column_style($i, "wrap") // $self->{"column_wrap"}) // $fcol_detect->[$i]{"wrap"} and defined $fcol_setwidths->[$i] and $fcol_setwidths->[$i] > 0
$self->get_eff_column_style($i, "wrap") $self->{"column_wrap"} $fcol_detect->[$i]{"wrap"} defined $fcol_setwidths->[$i] $fcol_setwidths->[$i] > 0
Truth table10%1/10
A // B // C and D and E
A= $self->get_eff_column_style($i, "wrap")B= $self->{"column_wrap"}C= $fcol_detect->[$i]{"wrap"}D= defined $fcol_setwidths->[$i]E= $fcol_setwidths->[$i] > 0
ABCDEresult
000XX0
1XX0X0
01X0X0
0010X0
1XX100
01X100
001100
1XX111
01X111
001111
1215 $fcol_detect->[$i]{wrap}) &&
1216 defined($fcol_setwidths->[$i]) &&
1217 $fcol_setwidths->[$i]>0) {
1218 0 for (0..@$frows-1) {
1219 0 $frows->[$_][$i] = $self->{_func_wrap}->(
1220 $frows->[$_][$i], $fcol_setwidths->[$i]);
1221 }
1222 }
1223 }
1224 }
1225  
1226 1 ▶sub _calc_table_width_height {
Subroutine _calc_table_width_height: called CC=22 SCAR=37.8
1227 1 my $self = shift;
1228  
1229 1 my $cols = $self->{columns};
1230 1 my $fcols = $self->{_draw}{fcols};
1231 1 my $frows = $self->{_draw}{frows};
1232 1 my $fcol_widths = $self->{_draw}{fcol_widths};
1233 1 my $fcol_lpads = $self->{_draw}{fcol_lpads};
1234 1 my $fcol_rpads = $self->{_draw}{fcol_rpads};
1235 1 my $frow_tpads = $self->{_draw}{frow_tpads};
1236 1 my $frow_bpads = $self->{_draw}{frow_bpads};
1237 1 my $frow_heights = $self->{_draw}{frow_heights};
1238  
1239 1 my $w = 0;
1240 1 ▶ $w += 1 if length($self->{border_style_obj}->get_border_char(char=>'v_l'));
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"border_style_obj"}->get_border_char("char", "v_l") 1 0 1
1241 1 my $has_vsep = length($self->{border_style_obj}->get_border_char(char=>'v_i'));
1242 1 for my $i (0..@$cols-1) {
1243 1 ▶ next unless grep { $_ eq $cols->[$i] } @$fcols;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $cols->[$i];} @$fcols 0 1 1
1244 1 $w += $fcol_lpads->[$i] + $fcol_widths->[$i] + $fcol_rpads->[$i];
1245 1 ▶ if ($i < @$cols-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$cols - 1) 0 1 1
1246 0 ▶ $w += 1 if $has_vsep;
Branch: 1 branch
BranchTrueFalseTotal
if $has_vsep 0 0 0
1247 }
1248 }
1249 1 ▶ $w += 1 if length($self->{border_style_obj}->get_border_char(char=>'v_r'));
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"border_style_obj"}->get_border_char("char", "v_r") 1 0 1
1250 1 $self->{_draw}{table_width} = $w;
1251  
1252 1 my $h = 0;
1253 1 ▶ $h += 1 if length($self->{border_style_obj}->get_border_char(char=>'rd_t')); # top border line
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"border_style_obj"}->get_border_char("char", "rd_t") 1 0 1
1254 $h += $self->{header_tpad} // $self->{header_vpad} //
1255 1 ▶ $self->{cell_tpad} // $self->{cell_vpad};
Condition33%3/9
(($self->{"header_tpad"} // $self->{"header_vpad"}) // $self->{"cell_tpad"}) // $self->{"cell_vpad"}
l!l&&r!l&&!r
010
($self->{"header_tpad"} // $self->{"header_vpad"}) // $self->{"cell_tpad"}
l!l&&r!l&&!r
001
$self->{"header_tpad"} // $self->{"header_vpad"}
l!l&&r!l&&!r
001
MC/DC0%0/4
(($self->{"header_tpad"} // $self->{"header_vpad"}) // $self->{"cell_tpad"}) // $self->{"cell_vpad"}
$self->{"header_tpad"} $self->{"header_vpad"} $self->{"cell_tpad"} $self->{"cell_vpad"}
Truth table20%1/5
A // B // C // D
A= $self->{"header_tpad"}B= $self->{"header_vpad"}C= $self->{"cell_tpad"}D= $self->{"cell_vpad"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1256 1 ▶ $h += $self->{_draw}{header_height} // 0;
Condition50%1/2
$self->{"_draw"}{"header_height"} // 0
l!l
10
MC/DC0%0/1
$self->{"_draw"}{"header_height"} // 0
$self->{"_draw"}{"header_height"}
Truth table50%1/2
A
A= $self->{"_draw"}{"header_height"}
Aresult
11
00
1257 $h += $self->{header_bpad} // $self->{header_vpad} //
1258 1 ▶ $self->{cell_bpad} // $self->{cell_vpad};
Condition33%3/9
(($self->{"header_bpad"} // $self->{"header_vpad"}) // $self->{"cell_bpad"}) // $self->{"cell_vpad"}
l!l&&r!l&&!r
010
($self->{"header_bpad"} // $self->{"header_vpad"}) // $self->{"cell_bpad"}
l!l&&r!l&&!r
001
$self->{"header_bpad"} // $self->{"header_vpad"}
l!l&&r!l&&!r
001
MC/DC0%0/4
(($self->{"header_bpad"} // $self->{"header_vpad"}) // $self->{"cell_bpad"}) // $self->{"cell_vpad"}
$self->{"header_bpad"} $self->{"header_vpad"} $self->{"cell_bpad"} $self->{"cell_vpad"}
Truth table20%1/5
A // B // C // D
A= $self->{"header_bpad"}B= $self->{"header_vpad"}C= $self->{"cell_bpad"}D= $self->{"cell_vpad"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1259 1 ▶ $h += 1 if length($self->{border_style_obj}->get_border_char(char=>'rv_l'));
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"border_style_obj"}->get_border_char("char", "rv_l") 1 0 1
1260 1 for my $i (0..@$frows-1) {
1261 2 ▶ $h += ($frow_tpads->[$i] // 0) +
Condition50%3/6
$frow_tpads->[$i] // 0
l!l
20
$frow_heights->[$i] // 0
l!l
20
$frow_bpads->[$i] // 0
l!l
20
MC/DC0%0/1
$frow_tpads->[$i] // 0
$frow_tpads->[$i]
MC/DC0%0/1
$frow_heights->[$i] // 0
$frow_heights->[$i]
MC/DC0%0/1
$frow_bpads->[$i] // 0
$frow_bpads->[$i]
Truth table50%1/2
A
A= $frow_tpads->[$i]
Aresult
11
00
Truth table50%1/2
A
A= $frow_heights->[$i]
Aresult
11
00
Truth table50%1/2
A
A= $frow_bpads->[$i]
Aresult
11
00
1262 ($frow_heights->[$i] // 0) +
1263 ($frow_bpads->[$i] // 0);
1264 2 ▶ $h += 1 if $self->_should_draw_row_separator($i);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_should_draw_row_separator($i) 0 2 2
1265 }
1266 1 ▶ $h += 1 if length($self->{border_style_obj}->get_border_char(char=>'ru_b'));
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"border_style_obj"}->get_border_char("char", "ru_b") 1 0 1
1267 1 $self->{_draw}{table_height} = $h;
1268 }
1269  
1270 # if there are text columns with no width set, and the column width is wider
1271 # than terminal, try to adjust widths so it fit into the terminal, if possible.
1272 # return 1 if widths (fcol_widths) adjusted.
1273 1 ▶sub _adjust_column_widths {
Subroutine _adjust_column_widths: called CC=21 SCAR=54.4
1274 1 my $self = shift;
1275  
1276 # try to find wrappable columns that do not have their widths set. currently
1277 # the algorithm is not proper, it just targets columns which are wider than
1278 # a hard-coded value (30). it should take into account the longest word in
1279 # the content/header, but this will require another pass at the text to
1280 # analyze it.
1281  
1282 1 my $fcols = $self->{_draw}{fcols};
1283 1 my $frows = $self->{_draw}{frows};
1284 1 my $fcol_setwidths = $self->{_draw}{fcol_setwidths};
1285 1 my $fcol_detect = $self->{_draw}{fcol_detect};
1286 1 my $fcol_widths = $self->{_draw}{fcol_widths};
1287 1 my %acols;
1288 my %origw;
1289 1 for my $i (0..@$fcols-1) {
1290 1 my $ci = $self->_colnum($fcols->[$i]);
1291 1 ▶ next if defined($fcol_setwidths->[$ci]) && $fcol_setwidths->[$ci]>0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fcol_setwidths->[$ci] and $fcol_setwidths->[$ci] > 0 0 1 1
Condition33%1/3
defined $fcol_setwidths->[$ci] and $fcol_setwidths->[$ci] > 0
!ll&&!rl&&r
100
MC/DC0%0/2
defined $fcol_setwidths->[$ci] and $fcol_setwidths->[$ci] > 0
defined $fcol_setwidths->[$ci] $fcol_setwidths->[$ci] > 0
Truth table33%1/3
A and B
A= defined $fcol_setwidths->[$ci]B= $fcol_setwidths->[$ci] > 0
ABresult
0X0
100
111
1292 1 ▶ next if $fcol_widths->[$ci] < 30;
Branch: 1 branch
BranchTrueFalseTotal
if $fcol_widths->[$ci] < 30 1 0 1
1293 next unless $self->get_eff_column_style($ci, 'wrap') //
1294 0 ▶ $self->{column_wrap} // $fcol_detect->[$ci]{wrap};
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_eff_column_style($ci, "wrap") // $self->{"column_wrap"}) // $fcol_detect->[$ci]{"wrap"} 0 0 0
Condition0%0/6
($self->get_eff_column_style($ci, "wrap") // $self->{"column_wrap"}) // $fcol_detect->[$ci]{"wrap"}
l!l&&r!l&&!r
000
$self->get_eff_column_style($ci, "wrap") // $self->{"column_wrap"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($self->get_eff_column_style($ci, "wrap") // $self->{"column_wrap"}) // $fcol_detect->[$ci]{"wrap"}
$self->get_eff_column_style($ci, "wrap") $self->{"column_wrap"} $fcol_detect->[$ci]{"wrap"}
Truth table0%0/4
A // B // C
A= $self->get_eff_column_style($ci, "wrap")B= $self->{"column_wrap"}C= $fcol_detect->[$ci]{"wrap"}
ABCresult
1XX1
01X1
0011
0000
1295 0 $acols{$ci}++;
1296 0 $origw{$ci} = $fcol_widths->[$ci];
1297 }
1298 1 ▶ return 0 unless %acols;
Branch: 1 branch
BranchTrueFalseTotal
unless %acols 1 0 1
1299  
1300 # only do this if table width exceeds terminal width
1301 0 my $termw = $self->term_width;
1302 0 ▶ return 0 unless $termw > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $termw > 0 0 0 0
1303 0 my $excess = $self->{_draw}{table_width} - $termw;
1304 0 ▶ return 0 unless $excess > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $excess > 0 0 0 0
1305  
1306 # reduce text columns proportionally
1307 0 my $w = 0; # total width of all to-be-adjusted columns
1308 0 $w += $fcol_widths->[$_] for keys %acols;
1309 0 ▶ return 0 unless $w > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $w > 0 0 0 0
1310 0 my $reduced = 0;
1311 REDUCE:
1312 0 while (1) {
1313 0 my $has_reduced;
1314 0 for my $ci (keys %acols) {
1315 0 ▶ last REDUCE if $reduced >= $excess;
Branch: 1 branch
BranchTrueFalseTotal
if $reduced >= $excess 0 0 0
1316 0 ▶ if ($fcol_widths->[$ci] > 30) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fcol_widths->[$ci] > 30) 0 0 0
1317 0 $fcol_widths->[$ci]--;
1318 0 $reduced++;
1319 0 $has_reduced++;
1320 }
1321 }
1322 0 ▶ last if !$has_reduced;
Branch: 1 branch
BranchTrueFalseTotal
unless $has_reduced 0 0 0
1323 }
1324  
1325 # reset widths
1326 0 for my $ci (keys %acols) {
1327 0 $fcol_setwidths->[$ci] = $fcol_widths->[$ci];
1328 0 $fcol_widths->[$ci] = 0; # reset
1329 }
1330  
1331 # wrap and set setwidths so it doesn't grow again during recalculate
1332 0 for my $ci (keys %acols) {
1333 0 ▶ next unless $origw{$ci} != $fcol_widths->[$ci];
Branch: 1 branch
BranchTrueFalseTotal
unless $origw{$ci} != $fcol_widths->[$ci] 0 0 0
1334 0 for (0..@$frows-1) {
1335 0 $frows->[$_][$ci] = $self->{_func_wrap}->(
1336 $frows->[$_][$ci], $fcol_setwidths->[$ci]);
1337 }
1338 }
1339  
1340 # recalculate column widths
1341 0 $self->_calc_row_widths_heights;
1342 0 $self->_calc_table_width_height;
1343 0 1;
1344 }
1345  
1346 # filter columns & rows, calculate widths/paddings, format data, put the results
1347 # in _draw (draw data) attribute.
1348 1 ▶sub _prepare_draw {
Subroutine _prepare_draw: called CC=1 SCAR=0.0
1349 1 my $self = shift;
1350  
1351 1 $self->{_draw} = {};
1352  
1353 1 $self->_read_style_envs;
1354 1 $self->_calc_fcols;
1355 1 $self->_calc_header_height;
1356 1 $self->_calc_frows;
1357 1 $self->_detect_column_types;
1358 1 $self->_apply_column_formats;
1359 1 $self->_apply_cell_formats;
1360 1 $self->_wrap_wrappable_columns;
1361 1 $self->_calc_row_widths_heights;
1362 1 $self->_calc_table_width_height;
1363 1 $self->_adjust_column_widths;
1364 }
1365  
1366 # push string into the drawing buffer. also updates "cursor" position.
1367 24 ▶sub draw_str {
Subroutine draw_str: called CC=3 SCAR=11.0
Pod undocumented
1368 24 my $self = shift;
1369 # currently x position is not recorded because this involves doing
1370 # ta_mbswidth() (or ta_mbswidth_height()) for every string, which is rather
1371 # expensive. so only the y position is recorded by counting newlines.
1372  
1373 24 for (@_) {
1374 24 my $num_nl = 0;
1375 24 ▶ $num_nl++ while /\r?\n/og;
Branch: 1 branch
BranchTrueFalseTotal
/\r?\n/go and do { ++$num_nl } 6 24 30
1376 24 push @{$self->{_draw}{buf}}, $_;
1377 24 $self->{_draw}{y} += $num_nl;
1378 }
1379 24 $self;
1380 }
1381  
1382 0 ▶sub draw_theme_color {
Subroutine draw_theme_color: not called CC=2 SCAR=17.9
Pod undocumented
1383 0 my $self = shift;
1384 0 my $c = $self->_color_theme_item_color_to_ansi(@_);
1385 0 ▶ $self->draw_str($c) if length($c);
Branch: 1 branch
BranchTrueFalseTotal
if length $c 0 0 0
1386 }
1387  
1388 18 ▶sub get_color_reset {
Subroutine get_color_reset: called CC=3 SCAR=16.5
Pod undocumented
1389 18 my $self = shift;
1390 18 ▶ return "" unless $self->use_color;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->use_color 18 0 18
1391 0 ▶ return "" if $self->{color_theme_obj}->get_struct->{_no_color};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"color_theme_obj"}->get_struct->{"_no_color"} 0 0 0
1392 0 "\e[0m";
1393 }
1394  
1395 18 ▶sub draw_color_reset {
Subroutine draw_color_reset: called CC=2 SCAR=7.1
Pod undocumented
1396 18 my $self = shift;
1397 18 my $c = $self->get_color_reset;
1398 18 ▶ $self->draw_str($c) if length($c);
Branch: 1 branch
BranchTrueFalseTotal
if length $c 0 18 18
1399 }
1400  
1401 # draw border character(s). drawing border character involves setting border
1402 # color, aside from drawing the actual characters themselves. arguments are list
1403 # of (y, x, n) tuples where y and x are the row and col number of border
1404 # character, n is the number of characters to print. n defaults to 1 if not
1405 # specified.
1406 9 ▶sub draw_border_char {
Subroutine draw_border_char: called CC=6 SCAR=18.8
Pod undocumented
1407 9 my $self = shift;
1408 9 ▶ my $args; $args = shift if ref($_[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 4 5 9
1409  
1410 9 ▶ while (my ($name, $n) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 15 9 24
1411 15 ▶ $n //= 1;
Condition100%2/2
$n //= 1
l!l
96
MC/DC100%1/1
$n //= 1
$n
Truth table100%2/2
A
A= $n
Aresult
11
00
1412 15 ▶ if (!$self->{use_color}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'use_color'}) { } 15 0 15
elsif ($args) { } 0 0 0
1413 # save some CPU cycles
1414 } elsif ($args) {
1415 0 $self->draw_theme_color('border',
1416 {table=>$self, border=>[$name, $n], %$args});
1417 } else {
1418 0 $self->draw_theme_color('border',
1419 {table=>$self, border=>[$name, $n]});
1420 }
1421 15 $self->draw_str($self->{border_style_obj}->get_border_char(char=>$name, repeat=>$n));
1422 15 $self->draw_color_reset;
1423 }
1424 }
1425  
1426 4 ▶sub _should_draw_row_separator {
Subroutine _should_draw_row_separator: called CC=4 SCAR=16.6
1427 4 my ($self, $i) = @_;
1428  
1429 4 ▶ return $i < @{$self->{_draw}{frows}}-1 &&
Condition33%2/6
$self->{"show_row_separator"} == 2 and grep {$_ == $i;} @{$$self{"_draw"}{"frow_separators"};} or $self->{"show_row_separator"} == 1
l!l&&r!l&&!r
002
$self->{"show_row_separator"} == 2 and grep {$_ == $i;} @{$$self{"_draw"}{"frow_separators"};}
!ll&&!rl&&r
020
MC/DC0%0/3
$self->{"show_row_separator"} == 2 and grep {$_ == $i;} @{$$self{"_draw"}{"frow_separators"};} or $self->{"show_row_separator"} == 1
$self->{"show_row_separator"} == 2 grep {$_ == $i;} @{$$self{"_draw"}{"frow_separators"};} $self->{"show_row_separator"} == 1
Truth table0%0/5
A and B or C
A= $self->{"show_row_separator"} == 2B= grep {$_ == $i;} @{$$self{"_draw"}{"frow_separators"};}C= $self->{"show_row_separator"} == 1
ABCresult
11X1
0X11
1011
0X00
1000
1430 0 (($self->{show_row_separator}==2 && (grep { $_ == $i } @{ $self->{_draw}{frow_separators} }))
1431 4 ▶ || $self->{show_row_separator}==1);
Condition66%2/3
$i < @{$self->{'_draw'}{'frows'};} - 1 && ($self->{'show_row_separator'} == 2 && grep({$_ == $i;} @{$$self{'_draw'}{'frow_separators'};}) || $self->{'show_row_separator'} == 1)
!ll&&!rl&&r
220
MC/DC50%1/2
$i < @{$self->{'_draw'}{'frows'};} - 1 && ($self->{'show_row_separator'} == 2 && grep({$_ == $i;} @{$$self{'_draw'}{'frow_separators'};}) || $self->{'show_row_separator'} == 1)
$i < @{$self->{'_draw'}{'frows'};} - 1 ($self->{'show_row_separator'} == 2 && grep({$_ == $i;} @{$$self{'_draw'}{'frow_separators'};}) || $self->{'show_row_separator'} == 1)
Truth table66%2/3
A && B
A= $i < @{$self->{'_draw'}{'frows'};} - 1B= ($self->{'show_row_separator'} == 2 && grep({$_ == $i;} @{$$self{'_draw'}{'frow_separators'};}) || $self->{'show_row_separator'} == 1)
ABresult
0X0
100
111
1432 }
1433  
1434 # apply align/valign, apply padding, apply default fgcolor/bgcolor to text,
1435 # truncate to specified cell's width & height
1436 3 ▶sub _get_cell_lines {
Subroutine _get_cell_lines: called CC=15 SCAR=33.0
1437 3 my $self = shift;
1438 #say "D: get_cell_lines ".join(", ", map{$_//""} @_);
1439 3 my ($text, $width, $height, $align, $valign,
1440 $lpad, $rpad, $tpad, $bpad, $color) = @_;
1441  
1442 3 my @lines;
1443 3 push @lines, "" for 1..$tpad;
1444 3 my @dlines = split(/\r?\n/, $text);
1445 3 ▶ @dlines = ("") unless @dlines;
Branch: 1 branch
BranchTrueFalseTotal
unless @dlines 0 3 3
1446 3 my ($la, $lb);
1447 3 ▶ $valign //= 'top';
Condition50%1/2
$valign //= "top"
l!l
30
MC/DC0%0/1
$valign //= "top"
$valign
Truth table50%1/2
A
A= $valign
Aresult
11
00
1448 3 ▶ if ($valign =~ /^[Bb]/o) { # bottom
Branch: 2 branches
BranchTrueFalseTotal
if ($valign =~ /^[Bb]/o) { } 0 3 3
elsif ($valign =~ /^[MmCc]/o) { } 0 3 3
1449 0 $la = $height-@dlines;
1450 0 $lb = 0;
1451 } elsif ($valign =~ /^[MmCc]/o) { # middle/center
1452 0 $la = int(($height-@dlines)/2);
1453 0 $lb = $height-@dlines-$la;
1454 } else { # top
1455 3 $la = 0;
1456 3 $lb = $height-@dlines;
1457 }
1458 3 push @lines, "" for 1..$la;
1459 3 push @lines, @dlines;
1460 3 push @lines, "" for 1..$lb;
1461 3 push @lines, "" for 1..$bpad;
1462  
1463 3 ▶ $align //= 'left';
Condition50%1/2
$align //= "left"
l!l
30
MC/DC0%0/1
$align //= "left"
$align
Truth table50%1/2
A
A= $align
Aresult
11
00
1464 3 ▶ my $pad = $align =~ /^[Ll]/o ? "right" :
Branch: 2 branches
BranchTrueFalseTotal
$align =~ /^[Ll]/o ? : 3 0 3
$align =~ /^[Rr]/o ? : 0 0 0
1465 ($align =~ /^[Rr]/o ? "left" : "center");
1466  
1467 3 for (@lines) {
1468 3 $_ = (" "x$lpad) . $self->{_func_pad}->($_, $width, $pad, " ", 1) . (" "x$rpad);
1469 3 ▶ if ($self->{use_color}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"use_color"}) 0 3 3
1470 # add default color
1471 0 ▶ s/\e\[0m(?=.)/\e[0m$color/g if length($color);
Branch: 1 branch
BranchTrueFalseTotal
if length $color 0 0 0
1472 0 $_ = $color . $_;
1473 }
1474 }
1475  
1476 3 \@lines;
1477 }
1478  
1479 1 ▶sub _get_header_cell_lines {
Subroutine _get_header_cell_lines: called CC=20 SCAR=42.2
1480 1 my ($self, $i) = @_;
1481  
1482 1 my $ct = $self->{color_theme};
1483  
1484 1 my $tmp;
1485 my $fgcolor;
1486 1 ▶ if (defined $self->{header_fgcolor}) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $self->{'header_fgcolor'}) { } 0 1 1
elsif (defined $self->{'cell_fgcolor'}) { } 0 1 1
elsif ($tmp = $self->_color_theme_item_color_to_ansi('header')) { } 0 1 1
elsif ($tmp = $self->_color_theme_item_color_to_ansi('cell')) { } 0 1 1
1487 0 $fgcolor = item_color_to_ansi($self->{header_fgcolor});
1488 } elsif (defined $self->{cell_fgcolor}) {
1489 0 $fgcolor = item_color_to_ansi($self->{cell_fgcolor});
1490 #} elsif (defined $self->{_draw}{fcol_detect}[$i]{fgcolor}) {
1491 # $fgcolor = item_color_to_ansi($self->{_draw}{fcol_detect}[$i]{fgcolor});
1492 } elsif ($tmp = $self->_color_theme_item_color_to_ansi('header')) {
1493 0 $fgcolor = $tmp;
1494 } elsif ($tmp = $self->_color_theme_item_color_to_ansi('cell')) {
1495 0 $fgcolor = $tmp;
1496 } else {
1497 1 $fgcolor = "";
1498 }
1499  
1500 1 my $bgcolor;
1501 1 ▶ if (defined $self->{header_bgcolor}) {
Branch: 5 branches
BranchTrueFalseTotal
if (defined $self->{'header_bgcolor'}) { } 0 1 1
elsif (defined $self->{'cell_bgcolor'}) { } 0 1 1
elsif (defined $self->{'_draw'}{'fcol_detect'}[$i]{'bgcolor'}) { } 0 1 1
elsif ($tmp = $self->_color_theme_item_color_to_ansi('header_bg', undef, 'bg')) { } 0 1 1
elsif ($tmp = $self->_color_theme_item_color_to_ansi('cell_bg', undef, 'bg')) { } 0 1 1
1502 0 $bgcolor = item_color_to_ansi($self->{header_bgcolor}, 'bg');
1503 } elsif (defined $self->{cell_bgcolor}) {
1504 0 $bgcolor = item_color_to_ansi($self->{cell_bgcolor}, 'bg');
1505 } elsif (defined $self->{_draw}{fcol_detect}[$i]{bgcolor}) {
1506 0 $bgcolor = item_color_to_ansi($self->{_draw}{fcol_detect}[$i]{bgcolor}, 'bg');
1507 } elsif ($tmp = $self->_color_theme_item_color_to_ansi('header_bg', undef, 'bg')) {
1508 0 $bgcolor = $tmp;
1509 } elsif ($tmp = $self->_color_theme_item_color_to_ansi('cell_bg', undef, 'bg')) {
1510 0 $bgcolor = $tmp;
1511 } else {
1512 1 $bgcolor = "";
1513 }
1514  
1515 my $align =
1516 $self->{header_align} //
1517 $self->{cell_align} //
1518 $self->{_draw}{fcol_detect}[$i]{align} //
1519 1 ▶ 'left';
Condition37%3/8
(($self->{"header_align"} // $self->{"cell_align"}) // $self->{"_draw"}{"fcol_detect"}[$i]{"align"}) // "left"
l!l
01
($self->{"header_align"} // $self->{"cell_align"}) // $self->{"_draw"}{"fcol_detect"}[$i]{"align"}
l!l&&r!l&&!r
001
$self->{"header_align"} // $self->{"cell_align"}
l!l&&r!l&&!r
001
MC/DC0%0/3
(($self->{"header_align"} // $self->{"cell_align"}) // $self->{"_draw"}{"fcol_detect"}[$i]{"align"}) // "left"
$self->{"header_align"} $self->{"cell_align"} $self->{"_draw"}{"fcol_detect"}[$i]{"align"}
Truth table25%1/4
A // B // C
A= $self->{"header_align"}B= $self->{"cell_align"}C= $self->{"_draw"}{"fcol_detect"}[$i]{"align"}
ABCresult
1XX1
01X1
0011
0000
1520 my $valign =
1521 $self->{header_valign} //
1522 $self->{cell_valign} //
1523 $self->{_draw}{fcol_detect}[$i]{valign} //
1524 1 ▶ 'top';
Condition37%3/8
(($self->{"header_valign"} // $self->{"cell_valign"}) // $self->{"_draw"}{"fcol_detect"}[$i]{"valign"}) // "top"
l!l
01
($self->{"header_valign"} // $self->{"cell_valign"}) // $self->{"_draw"}{"fcol_detect"}[$i]{"valign"}
l!l&&r!l&&!r
001
$self->{"header_valign"} // $self->{"cell_valign"}
l!l&&r!l&&!r
001
MC/DC0%0/3
(($self->{"header_valign"} // $self->{"cell_valign"}) // $self->{"_draw"}{"fcol_detect"}[$i]{"valign"}) // "top"
$self->{"header_valign"} $self->{"cell_valign"} $self->{"_draw"}{"fcol_detect"}[$i]{"valign"}
Truth table25%1/4
A // B // C
A= $self->{"header_valign"}B= $self->{"cell_valign"}C= $self->{"_draw"}{"fcol_detect"}[$i]{"valign"}
ABCresult
1XX1
01X1
0011
0000
1525  
1526 1 my $lpad = $self->{_draw}{fcol_lpads}[$i];
1527 1 my $rpad = $self->{_draw}{fcol_rpads}[$i];
1528 1 ▶ my $tpad = $self->{header_tpad} // $self->{header_vpad} // 0;
Condition40%2/5
($self->{"header_tpad"} // $self->{"header_vpad"}) // 0
l!l
01
$self->{"header_tpad"} // $self->{"header_vpad"}
l!l&&r!l&&!r
001
MC/DC0%0/2
($self->{"header_tpad"} // $self->{"header_vpad"}) // 0
$self->{"header_tpad"} $self->{"header_vpad"}
Truth table33%1/3
A // B
A= $self->{"header_tpad"}B= $self->{"header_vpad"}
ABresult
1X1
011
000
1529 1 ▶ my $bpad = $self->{header_bpad} // $self->{header_vpad} // 0;
Condition40%2/5
($self->{"header_bpad"} // $self->{"header_vpad"}) // 0
l!l
01
$self->{"header_bpad"} // $self->{"header_vpad"}
l!l&&r!l&&!r
001
MC/DC0%0/2
($self->{"header_bpad"} // $self->{"header_vpad"}) // 0
$self->{"header_bpad"} $self->{"header_vpad"}
Truth table33%1/3
A // B
A= $self->{"header_bpad"}B= $self->{"header_vpad"}
ABresult
1X1
011
000
1530  
1531 #use Data::Dump; print "D:header cell: "; dd {i=>$i, col=>$self->{columns}[$i], fgcolor=>$fgcolor, bgcolor=>$bgcolor};
1532 my $res = $self->_get_cell_lines(
1533 $self->{columns}[$i], # text
1534 $self->{_draw}{fcol_widths}[$i], # width
1535 $self->{_draw}{header_height}, # height
1536 1 $align, $valign, # aligns
1537 $lpad, $rpad, $tpad, $bpad, # paddings
1538 $fgcolor . $bgcolor);
1539 #use Data::Dump; print "D:res: "; dd $res;
1540 1 $res;
1541 }
1542  
1543 2 ▶sub _get_data_cell_lines {
Subroutine _get_data_cell_lines: called CC=23 SCAR=45.2
1544 2 my ($self, $y, $x) = @_;
1545  
1546 2 my $ct = $self->{color_theme};
1547 2 my $oy = $self->{_draw}{frow_orig_indices}[$y];
1548 2 my $cell = $self->{_draw}{frows}[$y][$x];
1549 my $args = {table=>$self, rownum=>$y, colnum=>$x, data=>$cell,
1550 2 orig_data=>$self->{rows}[$oy][$x]};
1551  
1552 2 my $tmp;
1553 my $fgcolor;
1554 2 ▶ if (defined ($tmp = $self->get_eff_cell_style($oy, $x, 'fgcolor'))) {
Branch: 6 branches
BranchTrueFalseTotal
if (defined($tmp = $self->get_eff_cell_style($oy, $x, 'fgcolor'))) { } 0 2 2
elsif (defined($tmp = $self->get_eff_row_style($oy, 'fgcolor'))) { } 0 2 2
elsif (defined($tmp = $self->get_eff_column_style($x, 'fgcolor'))) { } 0 2 2
elsif (defined($tmp = $self->{'cell_fgcolor'})) { } 0 2 2
elsif (defined($tmp = $self->{'_draw'}{'fcol_detect'}[$x]{'fgcolor'})) { } 0 2 2
elsif ($tmp = $self->_color_theme_item_color_to_ansi('cell', $args)) { } 0 2 2
1555 0 $fgcolor = item_color_to_ansi($tmp);
1556 } elsif (defined ($tmp = $self->get_eff_row_style($oy, 'fgcolor'))) {
1557 0 $fgcolor = item_color_to_ansi($tmp);
1558 } elsif (defined ($tmp = $self->get_eff_column_style($x, 'fgcolor'))) {
1559 0 $fgcolor = item_color_to_ansi($tmp);
1560 } elsif (defined ($tmp = $self->{cell_fgcolor})) {
1561 0 $fgcolor = item_color_to_ansi($tmp);
1562 } elsif (defined ($tmp = $self->{_draw}{fcol_detect}[$x]{fgcolor})) {
1563 0 $fgcolor = item_color_to_ansi($tmp);
1564 } elsif ($tmp = $self->_color_theme_item_color_to_ansi('cell', $args)) {
1565 0 $fgcolor = $tmp;
1566 } else {
1567 2 $fgcolor = "";
1568 }
1569  
1570 2 my $bgcolor;
1571 2 ▶ if (defined ($tmp = $self->get_eff_cell_style($oy, $x, 'bgcolor'))) {
Branch: 6 branches
BranchTrueFalseTotal
if (defined($tmp = $self->get_eff_cell_style($oy, $x, 'bgcolor'))) { } 0 2 2
elsif (defined($tmp = $self->get_eff_row_style($oy, 'bgcolor'))) { } 0 2 2
elsif (defined($tmp = $self->get_eff_column_style($x, 'bgcolor'))) { } 0 2 2
elsif (defined($tmp = $self->{'cell_bgcolor'})) { } 0 2 2
elsif (defined($tmp = $self->{'_draw'}{'fcol_detect'}[$x]{'bgcolor'})) { } 0 2 2
elsif ($tmp = $self->_color_theme_item_color_to_ansi('cell_bg', $args, 'bg')) { } 0 2 2
1572 0 $bgcolor = item_color_to_ansi($tmp, 'bg');
1573 } elsif (defined ($tmp = $self->get_eff_row_style($oy, 'bgcolor'))) {
1574 0 $bgcolor = item_color_to_ansi($tmp, 'bg');
1575 } elsif (defined ($tmp = $self->get_eff_column_style($x, 'bgcolor'))) {
1576 0 $bgcolor = item_color_to_ansi($tmp, 'bg');
1577 } elsif (defined ($tmp = $self->{cell_bgcolor})) {
1578 0 $bgcolor = item_color_to_ansi($tmp, 'bg');
1579 } elsif (defined ($tmp = $self->{_draw}{fcol_detect}[$x]{bgcolor})) {
1580 0 $bgcolor = item_color_to_ansi($tmp, 'bg');
1581 } elsif ($tmp = $self->_color_theme_item_color_to_ansi('cell_bg', $args, 'bg')) {
1582 0 $bgcolor = $tmp;
1583 } else {
1584 2 $bgcolor = "";
1585 }
1586  
1587 my $align =
1588 $self->get_eff_cell_style($oy, $x, 'align') //
1589 $self->get_eff_row_style($oy, 'align') //
1590 $self->get_eff_column_style($x, 'align') //
1591 $self->{cell_align} //
1592 $self->{_draw}{fcol_detect}[$x]{align} //
1593 2 ▶ 'left';
Condition35%5/14
(((($self->get_eff_cell_style($oy, $x, "align") // $self->get_eff_row_style($oy, "align")) // $self->get_eff_column_style($x, "align")) // $self->{"cell_align"}) // $self->{"_draw"}{"fcol_detect"}[$x]{"align"}) // "left"
l!l
02
((($self->get_eff_cell_style($oy, $x, "align") // $self->get_eff_row_style($oy, "align")) // $self->get_eff_column_style($x, "align")) // $self->{"cell_align"}) // $self->{"_draw"}{"fcol_detect"}[$x]{"align"}
l!l&&r!l&&!r
002
(($self->get_eff_cell_style($oy, $x, "align") // $self->get_eff_row_style($oy, "align")) // $self->get_eff_column_style($x, "align")) // $self->{"cell_align"}
l!l&&r!l&&!r
002
($self->get_eff_cell_style($oy, $x, "align") // $self->get_eff_row_style($oy, "align")) // $self->get_eff_column_style($x, "align")
l!l&&r!l&&!r
002
$self->get_eff_cell_style($oy, $x, "align") // $self->get_eff_row_style($oy, "align")
l!l&&r!l&&!r
002
MC/DC0%0/5
(((($self->get_eff_cell_style($oy, $x, "align") // $self->get_eff_row_style($oy, "align")) // $self->get_eff_column_style($x, "align")) // $self->{"cell_align"}) // $self->{"_draw"}{"fcol_detect"}[$x]{"align"}) // "left"
$self->get_eff_cell_style($oy, $x, "align") $self->get_eff_row_style($oy, "align") $self->get_eff_column_style($x, "align") $self->{"cell_align"} $self->{"_draw"}{"fcol_detect"}[$x]{"align"}
Truth table16%1/6
A // B // C // D // E
A= $self->get_eff_cell_style($oy, $x, "align")B= $self->get_eff_row_style($oy, "align")C= $self->get_eff_column_style($x, "align")D= $self->{"cell_align"}E= $self->{"_draw"}{"fcol_detect"}[$x]{"align"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1594 my $valign =
1595 $self->get_eff_cell_style($oy, $x, 'valign') //
1596 $self->get_eff_row_style($oy, 'valign') //
1597 $self->get_eff_column_style($x, 'valign') //
1598 $self->{cell_valign} //
1599 $self->{_draw}{fcol_detect}[$x]{valign} //
1600 2 ▶ 'top';
Condition35%5/14
(((($self->get_eff_cell_style($oy, $x, "valign") // $self->get_eff_row_style($oy, "valign")) // $self->get_eff_column_style($x, "valign")) // $self->{"cell_valign"}) // $self->{"_draw"}{"fcol_detect"}[$x]{"valign"}) // "top"
l!l
02
((($self->get_eff_cell_style($oy, $x, "valign") // $self->get_eff_row_style($oy, "valign")) // $self->get_eff_column_style($x, "valign")) // $self->{"cell_valign"}) // $self->{"_draw"}{"fcol_detect"}[$x]{"valign"}
l!l&&r!l&&!r
002
(($self->get_eff_cell_style($oy, $x, "valign") // $self->get_eff_row_style($oy, "valign")) // $self->get_eff_column_style($x, "valign")) // $self->{"cell_valign"}
l!l&&r!l&&!r
002
($self->get_eff_cell_style($oy, $x, "valign") // $self->get_eff_row_style($oy, "valign")) // $self->get_eff_column_style($x, "valign")
l!l&&r!l&&!r
002
$self->get_eff_cell_style($oy, $x, "valign") // $self->get_eff_row_style($oy, "valign")
l!l&&r!l&&!r
002
MC/DC0%0/5
(((($self->get_eff_cell_style($oy, $x, "valign") // $self->get_eff_row_style($oy, "valign")) // $self->get_eff_column_style($x, "valign")) // $self->{"cell_valign"}) // $self->{"_draw"}{"fcol_detect"}[$x]{"valign"}) // "top"
$self->get_eff_cell_style($oy, $x, "valign") $self->get_eff_row_style($oy, "valign") $self->get_eff_column_style($x, "valign") $self->{"cell_valign"} $self->{"_draw"}{"fcol_detect"}[$x]{"valign"}
Truth table16%1/6
A // B // C // D // E
A= $self->get_eff_cell_style($oy, $x, "valign")B= $self->get_eff_row_style($oy, "valign")C= $self->get_eff_column_style($x, "valign")D= $self->{"cell_valign"}E= $self->{"_draw"}{"fcol_detect"}[$x]{"valign"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1601 #say "D:y=$y, x=$x, align=$align, valign=$valign";
1602  
1603 2 my $lpad = $self->{_draw}{fcol_lpads}[$x];
1604 2 my $rpad = $self->{_draw}{fcol_rpads}[$x];
1605 2 my $tpad = $self->{_draw}{frow_tpads}[$y];
1606 2 my $bpad = $self->{_draw}{frow_bpads}[$y];
1607  
1608 my $res = $self->_get_cell_lines(
1609 $cell, # text
1610 $self->{_draw}{fcol_widths}[$x], # width
1611 2 $self->{_draw}{frow_heights}[$y], # height
1612 $align, $valign, # aligns
1613 $lpad, $rpad, $tpad, $bpad, # paddings
1614 $fgcolor . $bgcolor);
1615 2 $res;
1616 }
1617  
1618 1 ▶sub draw {
Subroutine draw: called CC=28 SCAR=36.3
Pod documented
1619 1 my ($self) = @_;
1620  
1621 1 $self->_prepare_draw;
1622  
1623 1 $self->{_draw}{buf} = []; # output buffer
1624 1 $self->{_draw}{y} = 0; # current line
1625  
1626 1 my $cols = $self->{columns};
1627 1 my $fcols = $self->{_draw}{fcols};
1628 1 my $frows = $self->{_draw}{frows};
1629 1 my $frow_heights = $self->{_draw}{frow_heights};
1630 1 my $frow_tpads = $self->{_draw}{frow_tpads};
1631 1 my $frow_bpads = $self->{_draw}{frow_bpads};
1632 1 my $fcol_lpads = $self->{_draw}{fcol_lpads};
1633 1 my $fcol_rpads = $self->{_draw}{fcol_rpads};
1634 1 my $fcol_widths = $self->{_draw}{fcol_widths};
1635  
1636 # draw border top line
1637 {
1638 1 ▶ last unless length($self->{border_style_obj}->get_border_char(char=>'rd_t'));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"border_style_obj"}->get_border_char("char", "rd_t") 0 1 1
1639 1 my @b;
1640 1 push @b, 'rd_t', 1;
1641 1 for my $i (0..@$fcols-1) {
1642 1 my $ci = $self->_colnum($fcols->[$i]);
1643 1 push @b, 'h_t',
1644 $fcol_lpads->[$ci] + $fcol_widths->[$ci] + $fcol_rpads->[$ci];
1645 1 ▶ push @b, 'hd_t', 1 if $i < @$fcols-1;
Branch: 1 branch
BranchTrueFalseTotal
if $i < @$fcols - 1 0 1 1
1646 }
1647 1 push @b, 'ld_t', 1;
1648 1 $self->draw_border_char(@b);
1649 1 $self->draw_str("\n");
1650 }
1651  
1652 # draw header
1653 1 ▶ if ($self->{show_header}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_header"}) 1 0 1
1654 1 my %seen;
1655 1 my $hcell_lines = []; # index = [fcolnum]
1656 1 ▶ if (@$fcols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$fcols) { } 1 0 1
1657 1 for my $i (0..@$fcols-1) {
1658 1 my $ci = $self->_colnum($fcols->[$i]);
1659 1 ▶ if (defined($seen{$i})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seen{$i}) 0 1 1
1660 0 $hcell_lines->[$i] = $hcell_lines->[$seen{$i}];
1661 }
1662 1 $seen{$i} = $ci;
1663 1 $hcell_lines->[$i] = $self->_get_header_cell_lines($ci);
1664 }
1665 } else {
1666 # so we can still draw header
1667 0 $hcell_lines->[0] = [""];
1668 }
1669 #use Data::Dump; print "D:hcell_lines: "; dd $hcell_lines;
1670 1 for my $l (0..@{ $hcell_lines->[0] }-1) {
1671 1 $self->draw_border_char('v_l');
1672 1 for my $i (0..@$fcols-1) {
1673 1 $self->draw_str($hcell_lines->[$i][$l]);
1674 1 $self->draw_color_reset;
1675 1 ▶ $self->draw_border_char('v_i') unless $i == @$fcols-1;
Branch: 1 branch
BranchTrueFalseTotal
unless $i == @$fcols - 1 0 1 1
1676 }
1677 1 $self->draw_border_char('v_r');
1678 1 $self->draw_str("\n");
1679 }
1680 }
1681  
1682 # draw header-data row separator
1683 1 ▶ if ($self->{show_header} && length($self->{border_style_obj}->get_border_char(char=>'rv_l'))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_header"} and length $self->{"border_style_obj"}->get_border_char("char", "rv_l")) 1 0 1
Condition33%1/3
$self->{"show_header"} and length $self->{"border_style_obj"}->get_border_char("char", "rv_l")
!ll&&!rl&&r
001
MC/DC0%0/2
$self->{"show_header"} and length $self->{"border_style_obj"}->get_border_char("char", "rv_l")
$self->{"show_header"} length $self->{"border_style_obj"}->get_border_char("char", "rv_l")
Truth table33%1/3
A and B
A= $self->{"show_header"}B= length $self->{"border_style_obj"}->get_border_char("char", "rv_l")
ABresult
0X0
100
111
1684 1 my @b;
1685 1 push @b, 'rv_l', 1;
1686 1 for my $i (0..@$fcols-1) {
1687 1 my $ci = $self->_colnum($fcols->[$i]);
1688 1 push @b, 'h_i',
1689 $fcol_lpads->[$ci] + $fcol_widths->[$ci] + $fcol_rpads->[$ci];
1690 1 ▶ push @b, 'hv_i', 1 unless $i==@$fcols-1;
Branch: 1 branch
BranchTrueFalseTotal
unless $i == @$fcols - 1 0 1 1
1691 }
1692 1 push @b, 'lv_r', 1;
1693 1 $self->draw_border_char(@b);
1694 1 $self->draw_str("\n");
1695 }
1696  
1697 # draw data rows
1698 {
1699 1 for my $r (0..@$frows-1) {
1700 #$self->draw_str("r$r");
1701 2 my $dcell_lines = []; # index = [fcolnum]
1702 2 my %seen;
1703 2 ▶ if (@$fcols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$fcols) { } 2 0 2
1704 2 for my $i (0..@$fcols-1) {
1705 2 my $ci = $self->_colnum($fcols->[$i]);
1706 2 ▶ if (defined($seen{$i})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seen{$i}) 0 2 2
1707 0 $dcell_lines->[$i] = $dcell_lines->[$seen{$i}];
1708 }
1709 2 $seen{$i} = $ci;
1710 2 $dcell_lines->[$i] = $self->_get_data_cell_lines($r, $ci);
1711 }
1712 } else {
1713 # so we can still print row
1714 0 $dcell_lines->[0] = [" "];
1715 }
1716 #use Data::Dump; print "TMP: dcell_lines: "; dd $dcell_lines;
1717 2 for my $l (0..@{ $dcell_lines->[0] }-1) {
1718 2 $self->draw_border_char({rownum=>$r}, 'v_l');
1719 2 for my $i (0..@$fcols-1) {
1720 2 $self->draw_str($dcell_lines->[$i][$l]);
1721 2 $self->draw_color_reset;
1722 2 ▶ $self->draw_border_char({rownum=>$r}, 'v_i')
Branch: 1 branch
BranchTrueFalseTotal
unless $i == @$fcols - 1 0 2 2
1723 unless $i == @$fcols-1;
1724 }
1725 2 $self->draw_border_char({rownum=>$r}, 'v_r');
1726 2 $self->draw_str("\n");
1727 }
1728  
1729 # draw separators between row
1730 2 ▶ if ($self->_should_draw_row_separator($r)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_should_draw_row_separator($r)) 0 2 2
1731 0 my @b;
1732 0 push @b, 'rv_l', 1;
1733 0 for my $i (0..@$fcols-1) {
1734 0 my $ci = $self->_colnum($fcols->[$i]);
1735 0 push @b, 'h_i',
1736 $fcol_lpads->[$ci] + $fcol_widths->[$ci] +
1737 $fcol_rpads->[$ci];
1738 0 ▶ push @b, ($i==@$fcols-1 ? 'lv_r' : 'hv_i'), 1;
Branch: 1 branch
BranchTrueFalseTotal
$i == @$fcols - 1 ? : 0 0 0
1739 }
1740 0 $self->draw_border_char({rownum=>$r}, @b);
1741 0 $self->draw_str("\n");
1742 }
1743 } # for frow
1744 }
1745  
1746 # draw border bottom line
1747 {
1748 1 ▶ last unless length($self->{border_style_obj}->get_border_char(char=>'ru_b'));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"border_style_obj"}->get_border_char("char", "ru_b") 0 1 1
1749 1 my @b;
1750 1 push @b, 'ru_b', 1;
1751 1 for my $i (0..@$fcols-1) {
1752 1 my $ci = $self->_colnum($fcols->[$i]);
1753 1 push @b, 'h_b',
1754 $fcol_lpads->[$ci] + $fcol_widths->[$ci] + $fcol_rpads->[$ci];
1755 1 ▶ push @b, 'hu_b', 1 unless $i == @$fcols-1;
Branch: 1 branch
BranchTrueFalseTotal
unless $i == @$fcols - 1 0 1 1
1756 }
1757 1 push @b, 'lu_b', 1;
1758 1 $self->draw_border_char(@b);
1759 1 $self->draw_str("\n");
1760 }
1761  
1762 1 join "", @{$self->{_draw}{buf}};
1763 }
1764  
1765 3 1;
1766 # ABSTRACT: Create nice formatted tables using extended ASCII and ANSI colors
1767  
1768 __END__
↑ Summary Text/ANSITable/StyleSet/AltRow.pm »