blib/lib/Term/Fabulous/Widget/Table/Borders.pm

filter: Statementstmt 100% 173 / 173 Branchbran 96.0% 121 / 126 Conditioncond 81.0% 107 / 132 MC/DCmcdc 67.5% 54 / 80 Subroutinesub 100% 33 / 33 Podpod 100% 1 / 1 totaltotal 89.7% 489 / 545 CC 117 SCAR 26.0
CC
117
Cov
93%
resolve_borders
31.4
__ANON__
16.0
__ANON__
16.0
CRAP 13.5
« blib/lib/Term/Fabulous/Render/Target/Mask.pm ↑ Summary blib/lib/Term/Fabulous/Chart/Marker.pm »
1 package Term::Fabulous::Widget::Table::Borders;
2  
3 1 ▶use v5.32;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.05';
9  
10 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our @EXPORT_OK = qw(resolve_borders);
12  
13 1 ▶use List::Util qw(any first);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Term::Fabulous::Enum::BorderStyle;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 my $HIDDEN = Term::Fabulous::Enum::BorderStyle->Hidden;
18 1 my $BLANK = Term::Fabulous::Enum::BorderStyle->Blank;
19  
20 99 ▶sub _is_line ($style) {
Subroutine _is_line: called CC=3 SCAR=11.1
21 99 ▶ return defined $style && refaddr($style) != refaddr($HIDDEN) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $style && builtin::refaddr($style) != builtin::refaddr($HIDDEN) ? : 96 3 99
Condition66%2/3
defined $style and builtin::refaddr($style) != builtin::refaddr($HIDDEN)
!ll&&!rl&&r
0396
MC/DC50%1/2
defined $style and builtin::refaddr($style) != builtin::refaddr($HIDDEN)
defined $style builtin::refaddr($style) != builtin::refaddr($HIDDEN)
Truth table66%2/3
A and B
A= defined $styleB= builtin::refaddr($style) != builtin::refaddr($HIDDEN)
ABresult
0X0
100
111
22 }
23  
24 # Whether a style has joint glyphs, so that its lines join with others.
25 118 ▶sub _joins ($style) {
Subroutine _joins: called CC=2 SCAR=6.9
26 118 ▶ return defined $style->joints ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $style->joints ? : 94 24 118
27 }
28  
29 # Whether a frame side is drawn on the background outside the table
30 # (see Term::Fabulous::Role::HasBorderStyle/outer_border_sides). Line
31 # styles are, so that highlights stop at the frame. Block styles (Outer,
32 # Inner, Thick, ...) keep the backgrounds their glyphs are made for: a
33 # side whose glyph sits on the cell's own background stays inside, so the
34 # cells' colors reach the frame; one whose glyph sits on the background
35 # beside the box (location 1 or 2) is outside, and so are the cells of
36 # other lines that end on it.
37 65 ▶sub _drawn_outside ( $style, $side ) {
Subroutine _drawn_outside: called CC=7 SCAR=19.5
38 65 ▶ return 1 if _joins($style);
Branch: 1 branch
BranchTrueFalseTotal
if _joins($style) 53 12 65
39 12 ▶ my $location
Branch: 3 branches
BranchTrueFalseTotal
$side eq 'top' ? : 3 9 12
$side eq 'bottom' ? : 3 6 9
$side eq 'left' ? : 3 3 6
40 = $side eq 'top' ? ( $style->get_top_locations )[1]
41 : $side eq 'bottom' ? ( $style->get_bottom_locations )[1]
42 : $side eq 'left' ? $style->get_left_locations
43 : $style->get_right_locations;
44 12 ▶ return $location == 1 || $location == 2 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$location == 1 || $location == 2 ? : 4 8 12
Condition66%2/3
$location == 1 or $location == 2
l!l&&r!l&&!r
408
MC/DC50%1/2
$location == 1 or $location == 2
$location == 1 $location == 2
Truth table66%2/3
A or B
A= $location == 1B= $location == 2
ABresult
1X1
011
000
45 }
46  
47 # The first style the levels name, from the most specific: a level is an
48 # array of candidates, the last one winning within the level (the cell
49 # below, or to the right). Hidden ends the search: there is no line.
50 134 ▶sub _first_style (@levels) {
Subroutine _first_style: called CC=4 SCAR=13.9
51 134 foreach my $level (@levels) {
52 512 ▶ my $style = first { defined } reverse @$level;
Subroutine __ANON__: called CC=1 SCAR=0.0
53 512 ▶ return _is_line($style) ? $style : undef if defined $style;
Branch: 2 branches
BranchTrueFalseTotal
if defined $style 99 413 512
_is_line($style) ? : 96 3 99
54 }
55 35 return undef;
56 }
57  
58 # Works out the lines of a table. Takes
59 # columns => the number of grid columns
60 # header => how many of the lines are header lines (they come first)
61 # gutter => whether a scrollbar column follows the last grid column
62 # table => { border_top, border_right, border_bottom, border_left,
63 # column_lines, row_lines, header_line }
64 # column_styles => [ per column { border_left, border_right, row_lines } ]
65 # lines => [ per line { spanning, ledge, style => { border_top,
66 # border_right, border_bottom, border_left, column_lines },
67 # cells => [ per cell { border_top, border_right,
68 # border_bottom, border_left } ] } ] (a spanning line has
69 # one cell; a ledge is the first or the last line, holds
70 # nothing and has no line between itself and its neighbour,
71 # so it draws the frame's top or bottom and nothing else)
72 # and returns { lines => per line, per cell { sides => { top, right,
73 # bottom, left } (a BorderStyle per drawn side, Blank where a line passes
74 # elsewhere but not here), corners => { top_left, ... } (the glyph of
75 # every drawn corner that does not keep the glyph of its style), outer =>
76 # [ the frame sides drawn outside ] }, gutter => the same for the strips
77 # of the scrollbar column, { header, body, footer }, or undef }.
78 10 ▶sub resolve_borders (%args) {
Subroutine resolve_borders: called CC=31 SCAR=34.5
Pod documented
79 10 my ( $columns, $lines ) = @args{qw(columns lines)};
80 10 ▶ my $header_lines = $args{header} // 0;
Condition100%2/2
$args{"header"} // 0
l!l
46
MC/DC100%1/1
$args{"header"} // 0
$args{"header"}
Truth table100%2/2
A
A= $args{"header"}
Aresult
11
00
81 10 ▶ my $gutter = $args{gutter} // 0;
Condition100%2/2
$args{"gutter"} // 0
l!l
19
MC/DC100%1/1
$args{"gutter"} // 0
$args{"gutter"}
Truth table100%2/2
A
A= $args{"gutter"}
Aresult
11
00
82 10 ▶ my $table = $args{table} // {};
Condition50%1/2
$args{"table"} // {}
l!l
100
MC/DC0%0/1
$args{"table"} // {}
$args{"table"}
Truth table50%1/2
A
A= $args{"table"}
Aresult
11
00
83 10 ▶ my $column_style = $args{column_styles} // [];
Condition100%2/2
$args{"column_styles"} // []
l!l
19
MC/DC100%1/1
$args{"column_styles"} // []
$args{"column_styles"}
Truth table100%2/2
A
A= $args{"column_styles"}
Aresult
11
00
84 10 my $last_line = $#$lines;
85 10 my $line_count = scalar @$lines;
86  
87 10 my @ledges = grep { $lines->[$_]{ledge} } 0 .. $last_line;
88 10 ▶ die "Term::Fabulous::Widget::Table::Borders: a ledge must be the first or the last line" if grep { $_ != 0 && $_ != $last_line } @ledges;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ != 0 and $_ != $last_line;} @ledges 1 9 10
Condition100%3/3
$_ != 0 && $_ != $last_line
!ll&&!rl&&r
121
MC/DC100%2/2
$_ != 0 && $_ != $last_line
$_ != 0 $_ != $last_line
Truth table100%3/3
A && B
A= $_ != 0B= $_ != $last_line
ABresult
0X0
100
111
89  
90 184 ▶ my $cell_style = sub ( $line, $column ) {
Subroutine __ANON__: called CC=4 SCAR=13.9
91 184 ▶ my $cells = $lines->[$line]{cells} // [];
Condition100%2/2
$lines->[$line]{"cells"} // []
l!l
20164
MC/DC100%1/1
$lines->[$line]{"cells"} // []
$lines->[$line]{"cells"}
Truth table100%2/2
A
A= $lines->[$line]{"cells"}
Aresult
11
00
92 184 ▶ return ( $lines->[$line]{spanning} ? $cells->[0] : $cells->[$column] ) // {};
Branch: 1 branch
BranchTrueFalseTotal
$lines->[$line]{'spanning'} ? : 6 178 184
Condition100%2/2
($lines->[$line]{"spanning"} ? $cells->[0] : $cells->[$column]) // {}
l!l
20164
MC/DC100%1/1
($lines->[$line]{"spanning"} ? $cells->[0] : $cells->[$column]) // {}
($lines->[$line]{"spanning"} ? $cells->[0] : $cells->[$column])
Truth table100%2/2
A
A= ($lines->[$line]{"spanning"} ? $cells->[0] : $cells->[$column])
Aresult
11
00
93 9 };
94 9 ▶ my $row_style = sub ($line) { $lines->[$line]{style} // {} };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$lines->[$line]{"style"} // {}
l!l
14147
MC/DC100%1/1
$lines->[$line]{"style"} // {}
$lines->[$line]{"style"}
Truth table100%2/2
A
A= $lines->[$line]{"style"}
Aresult
11
00
95 9 ▶ my $is_ledge = sub ($line) { $line >= 0 && $line < $line_count && $lines->[$line]{ledge} ? 1 : 0 };
Subroutine __ANON__: called CC=4 SCAR=14.9
Branch: 1 branch
BranchTrueFalseTotal
$line >= 0 && $line < $line_count && $lines->[$line]{'ledge'} ? : 5 60 65
Condition50%3/6
$line >= 0 and $line < $line_count and $lines->[$line]{"ledge"}
!ll&&!rl&&r
0605
$line >= 0 and $line < $line_count
!ll&&!rl&&r
0065
MC/DC33%1/3
$line >= 0 and $line < $line_count and $lines->[$line]{"ledge"}
$line >= 0 $line < $line_count $lines->[$line]{"ledge"}
Truth table50%2/4
A and B and C
A= $line >= 0B= $line < $line_countC= $lines->[$line]{"ledge"}
ABCresult
0XX0
10X0
1100
1111
96  
97 # The horizontal segment above line $boundary ($line_count: below the
98 # last line) in a column ($columns: in the scrollbar column, which has
99 # no cells and no column style).
100 71 ▶ my $horizontal = sub ( $boundary, $column ) {
Subroutine __ANON__: called CC=16 SCAR=27.7
101 71 my ( $above, $below ) = ( $boundary - 1, $boundary );
102 71 ▶ my $inner = $boundary > 0 && $boundary < $line_count;
Condition100%3/3
$boundary > 0 && $boundary < $line_count
!ll&&!rl&&r
191933
MC/DC100%2/2
$boundary > 0 && $boundary < $line_count
$boundary > 0 $boundary < $line_count
Truth table100%3/3
A && B
A= $boundary > 0B= $boundary < $line_count
ABresult
0X0
100
111
103 71 ▶ return undef if $inner && ( $is_ledge->($above) || $is_ledge->($below) );
Branch: 1 branch
BranchTrueFalseTotal
if $inner and &$is_ledge($above) || &$is_ledge($below) 5 66 71
Condition100%6/6
$inner and &$is_ledge($above) || &$is_ledge($below)
!ll&&!rl&&r
38285
&$is_ledge($above) or &$is_ledge($below)
l!l&&r!l&&!r
1428
MC/DC100%3/3
$inner and &$is_ledge($above) || &$is_ledge($below)
$inner &$is_ledge($above) &$is_ledge($below)
Truth table100%4/4
A and B or C
A= $innerB= &$is_ledge($above)C= &$is_ledge($below)
ABCresult
0XX0
1000
11X1
1011
104 66 ▶ my @cells = ( ( $above >= 0 ? $cell_style->( $above, $column )->{border_bottom} : undef ), ( $below < $line_count ? $cell_style->( $below, $column )->{border_top} : undef ) );
Branch: 2 branches
BranchTrueFalseTotal
$above >= 0 ? : 47 19 66
$below < $line_count ? : 47 19 66
105 66 ▶ my @rows = ( ( $above >= 0 ? $row_style->($above)->{border_bottom} : undef ), ( $below < $line_count ? $row_style->($below)->{border_top} : undef ) );
Branch: 2 branches
BranchTrueFalseTotal
$above >= 0 ? : 47 19 66
$below < $line_count ? : 47 19 66
106 66 ▶ my @columns = $inner && $boundary != $header_lines ? ( ( $column_style->[$column] // {} )->{row_lines} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$inner && $boundary != $header_lines ? : 21 45 66
Condition100%5/5
$inner and $boundary != $header_lines
!ll&&!rl&&r
38721
$column_style->[$column] // {}
l!l
615
MC/DC100%2/2
$inner and $boundary != $header_lines
$inner $boundary != $header_lines
MC/DC100%1/1
$column_style->[$column] // {}
$column_style->[$column]
Truth table100%3/3
A and B
A= $innerB= $boundary != $header_lines
ABresult
0X0
100
111
Truth table100%2/2
A
A= $column_style->[$column]
Aresult
11
00
107 my $table_line
108 = $boundary == 0 ? $table->{border_top}
109 : $boundary == $line_count ? $table->{border_bottom}
110 : $boundary == $header_lines ? $table->{header_line} // $table->{row_lines}
111 66 ▶ : $table->{row_lines};
Branch: 3 branches
BranchTrueFalseTotal
$boundary == 0 ? : 19 47 66
$boundary == $line_count ? : 19 28 47
$boundary == $header_lines ? : 7 21 28
Condition33%1/3
$table->{"header_line"} // $table->{"row_lines"}
l!l&&r!l&&!r
700
MC/DC0%0/2
$table->{"header_line"} // $table->{"row_lines"}
$table->{"header_line"} $table->{"row_lines"}
Truth table33%1/3
A // B
A= $table->{"header_line"}B= $table->{"row_lines"}
ABresult
1X1
011
000
112 66 return _first_style( \@cells, \@rows, \@columns, [$table_line] );
113 9 };
114  
115 # The vertical segment of a line left of grid column $boundary
116 # ($columns: right of the last column, which is no line when the
117 # scrollbar column follows; the strips draw the frame there).
118 72 ▶ my $vertical = sub ( $line, $boundary ) {
Subroutine __ANON__: called CC=16 SCAR=27.7
119 72 ▶ return undef if $gutter && $boundary == $columns;
Branch: 1 branch
BranchTrueFalseTotal
if $gutter and $boundary == $columns 4 68 72
Condition100%3/3
$gutter and $boundary == $columns
!ll&&!rl&&r
6084
MC/DC100%2/2
$gutter and $boundary == $columns
$gutter $boundary == $columns
Truth table100%3/3
A and B
A= $gutterB= $boundary == $columns
ABresult
0X0
100
111
120 68 my $spanning = $lines->[$line]{spanning};
121 68 ▶ my $outer = $boundary == 0 || $boundary == $columns;
Condition100%3/3
$boundary == 0 || $boundary == $columns
l!l&&r!l&&!r
242024
MC/DC100%2/2
$boundary == 0 || $boundary == $columns
$boundary == 0 $boundary == $columns
Truth table100%3/3
A || B
A= $boundary == 0B= $boundary == $columns
ABresult
1X1
011
000
122 68 ▶ return undef if $spanning && !$outer;
Branch: 1 branch
BranchTrueFalseTotal
if $spanning and not $outer 1 67 68
Condition100%3/3
$spanning and not $outer
!ll&&!rl&&r
6521
MC/DC100%2/2
$spanning and not $outer
$spanning not $outer
Truth table100%3/3
A and not(B)
A= $spanningB= not $outer
ABresult
0X0
100
111
123 my @cells = (
124 ( $boundary > 0 ? $cell_style->( $line, $boundary - 1 )->{border_right} : undef ),
125 67 ▶ ( $boundary < $columns ? $cell_style->( $line, $boundary )->{border_left} : undef ),
Branch: 2 branches
BranchTrueFalseTotal
$boundary > 0 ? : 43 24 67
$boundary < $columns ? : 47 20 67
126 );
127 67 my $row = $row_style->($line);
128 my @rows
129 = $boundary == 0 ? ( $row->{border_left} )
130 : $boundary == $columns ? ( $row->{border_right} )
131 67 ▶ : ( $row->{column_lines} );
Branch: 2 branches
BranchTrueFalseTotal
$boundary == 0 ? : 24 43 67
$boundary == $columns ? : 20 23 43
132 my @column_levels = (
133 ( $boundary > 0 ? ( $column_style->[ $boundary - 1 ] // {} )->{border_right} : undef ),
134 67 ▶ ( $boundary < $columns ? ( $column_style->[$boundary] // {} )->{border_left} : undef ),
Branch: 2 branches
BranchTrueFalseTotal
$boundary > 0 ? : 43 24 67
$boundary < $columns ? : 47 20 67
Condition100%4/4
$$column_style[$boundary - 1] // {}
l!l
835
$column_style->[$boundary] // {}
l!l
839
MC/DC100%1/1
$$column_style[$boundary - 1] // {}
$$column_style[$boundary - 1]
MC/DC100%1/1
$column_style->[$boundary] // {}
$column_style->[$boundary]
Truth table100%2/2
A
A= $$column_style[$boundary - 1]
Aresult
11
00
Truth table100%2/2
A
A= $column_style->[$boundary]
Aresult
11
00
135 );
136 67 ▶ my $table_line = $boundary == 0 ? $table->{border_left} : $boundary == $columns ? $table->{border_right} : $table->{column_lines};
Branch: 2 branches
BranchTrueFalseTotal
$boundary == 0 ? : 24 43 67
$boundary == $columns ? : 20 23 43
137 67 return _first_style( \@cells, \@rows, \@column_levels, [$table_line] );
138 9 };
139  
140 9 my ( @h, @v, @h_gutter );
141 9 foreach my $boundary ( 0 .. $line_count ) {
142 33 $h[$boundary] = [ map { $horizontal->( $boundary, $_ ) } 0 .. $columns - 1 ];
143 33 ▶ $h_gutter[$boundary] = $gutter ? $horizontal->( $boundary, $columns ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$gutter ? : 5 28 33
144 }
145 9 foreach my $line ( 0 .. $last_line ) {
146 24 $v[$line] = [ map { $vertical->( $line, $_ ) } 0 .. $columns ];
147 }
148 my @row_line_exists = map {
149 9 my $boundary = $_;
150 33 ▶ ( any { defined } @{ $h[$boundary] }, $h_gutter[$boundary] ) ? 1 : 0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
&any(sub { defined $_; } , @{$h[$boundary];}, $h_gutter[$boundary]) ? : 22 11 33
151 } 0 .. $line_count;
152 my @column_line_exists = map {
153 9 my $boundary = $_;
154 27 ▶ ( any { defined $v[$_][$boundary] } 0 .. $last_line ) ? 1 : 0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
&any(sub { defined $v[$_][$boundary]; } , 0 .. $last_line) ? : 19 8 27
155 } 0 .. $columns;
156  
157 # Who draws a horizontal boundary: the line below it, except that a
158 # boundary above a spanning line is drawn by the (non-spanning) line
159 # above it, the last boundary by the last line, and the boundary below
160 # the header by the header, which does not scroll.
161 30 ▶ my $drawn_as_bottom = sub ($boundary) {
Subroutine __ANON__: called CC=6 SCAR=17.9
162 30 ▶ return 1 if $boundary == $line_count;
Branch: 1 branch
BranchTrueFalseTotal
if $boundary == $line_count 7 23 30
163 23 ▶ return 0 if $boundary == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $boundary == 0 7 16 23
164 16 ▶ return 1 if $boundary == $header_lines;
Branch: 1 branch
BranchTrueFalseTotal
if $boundary == $header_lines 6 10 16
165 10 ▶ return $lines->[$boundary]{spanning} && !$lines->[ $boundary - 1 ]{spanning} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$lines->[$boundary]{'spanning'} && !$$lines[$boundary - 1]{'spanning'} ? : 2 8 10
Condition66%2/3
$lines->[$boundary]{"spanning"} and not $$lines[$boundary - 1]{"spanning"}
!ll&&!rl&&r
802
MC/DC50%1/2
$lines->[$boundary]{"spanning"} and not $$lines[$boundary - 1]{"spanning"}
$lines->[$boundary]{"spanning"} not $$lines[$boundary - 1]{"spanning"}
Truth table66%2/3
A and not(B)
A= $lines->[$boundary]{"spanning"}B= not $$lines[$boundary - 1]{"spanning"}
ABresult
0X0
100
111
166 9 };
167  
168 116 ▶ my $vertical_arm = sub ( $line, $boundary ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
169 116 ▶ return undef if $line < 0 || $line > $last_line;
Branch: 1 branch
BranchTrueFalseTotal
if $line < 0 or $line > $last_line 36 80 116
Condition100%3/3
$line < 0 or $line > $last_line
l!l&&r!l&&!r
181880
MC/DC100%2/2
$line < 0 or $line > $last_line
$line < 0 $line > $last_line
Truth table100%3/3
A or B
A= $line < 0B= $line > $last_line
ABresult
1X1
011
000
170 80 return $v[$line][$boundary];
171 9 };
172 116 ▶ my $horizontal_arm = sub ( $boundary, $column ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
173 116 ▶ return undef if $column < 0 || $column >= $columns;
Branch: 1 branch
BranchTrueFalseTotal
if $column < 0 or $column >= $columns 40 76 116
Condition100%3/3
$column < 0 or $column >= $columns
l!l&&r!l&&!r
221876
MC/DC100%2/2
$column < 0 or $column >= $columns
$column < 0 $column >= $columns
Truth table100%3/3
A or B
A= $column < 0B= $column >= $columns
ABresult
1X1
011
000
174 76 return $h[$boundary][$column];
175 9 };
176  
177 # The glyph of a point of the outer frame when the frame's style has no
178 # joints (Outer, Inner, Thick, ...): the frame runs on with its straight
179 # edge glyph where an inner line meets it, and keeps its own corner
180 # glyphs at the table's corners (undef: no glyph of the table's own).
181 # Returns ( 1, $glyph ) for such a point, () for any other.
182 61 ▶ my $frame_point = sub ( $boundary, $grid_line, $arms ) {
Subroutine __ANON__: called CC=15 SCAR=27.1
183 61 my $on_top = $boundary == 0;
184 61 my $on_bottom = $boundary == $line_count;
185 61 ▶ my $on_side = $grid_line == 0 || $grid_line == $columns;
Condition100%3/3
$grid_line == 0 || $grid_line == $columns
l!l&&r!l&&!r
222118
MC/DC100%2/2
$grid_line == 0 || $grid_line == $columns
$grid_line == 0 $grid_line == $columns
Truth table100%3/3
A || B
A= $grid_line == 0B= $grid_line == $columns
ABresult
1X1
011
000
186 my $edge
187 = $on_top || $on_bottom ? $arms->{left} // $arms->{right}
188 : $on_side ? $arms->{up} // $arms->{down}
189 61 ▶ : undef;
Branch: 2 branches
BranchTrueFalseTotal
$on_top || $on_bottom ? : 38 23 61
$on_side ? : 15 8 23
Condition66%6/9
$on_top or $on_bottom
l!l&&r!l&&!r
191923
$arms->{"left"} // $arms->{"right"}
l!l&&r!l&&!r
24140
$arms->{"up"} // $arms->{"down"}
l!l&&r!l&&!r
1500
MC/DC100%2/2
$on_top or $on_bottom
$on_top $on_bottom
MC/DC0%0/2
$arms->{"left"} // $arms->{"right"}
$arms->{"left"} $arms->{"right"}
MC/DC0%0/2
$arms->{"up"} // $arms->{"down"}
$arms->{"up"} $arms->{"down"}
Truth table100%3/3
A or B
A= $on_topB= $on_bottom
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $arms->{"left"}B= $arms->{"right"}
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $arms->{"up"}B= $arms->{"down"}
ABresult
1X1
011
000
190 61 ▶ return () unless defined $edge && !_joins($edge);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $edge and not _joins($edge) 49 12 61
Condition100%3/3
defined $edge and not _joins($edge)
!ll&&!rl&&r
84112
MC/DC100%2/2
defined $edge and not _joins($edge)
defined $edge not _joins($edge)
Truth table100%3/3
A and not(B)
A= defined $edgeB= not _joins($edge)
ABresult
0X0
100
111
191 12 ▶ return ( 1, undef ) if ( $on_top || $on_bottom ) && $on_side;
Branch: 1 branch
BranchTrueFalseTotal
if $on_top || $on_bottom and $on_side 8 4 12
Condition100%6/6
$on_top || $on_bottom and $on_side
!ll&&!rl&&r
228
$on_top or $on_bottom
l!l&&r!l&&!r
552
MC/DC100%3/3
$on_top || $on_bottom and $on_side
$on_top $on_bottom $on_side
Truth table100%5/5
A or B and C
A= $on_topB= $on_bottomC= $on_side
ABCresult
00X0
1X00
0100
1X11
0111
192 4 ▶ return ( 1, ( $edge->get_top_glyphs )[1] ) if $on_top;
Branch: 1 branch
BranchTrueFalseTotal
if $on_top 1 3 4
193 3 ▶ return ( 1, ( $edge->get_bottom_glyphs )[1] ) if $on_bottom;
Branch: 1 branch
BranchTrueFalseTotal
if $on_bottom 1 2 3
194 2 ▶ return ( 1, ( $grid_line == 0 ? $edge->get_left_glyphs : $edge->get_right_glyphs ) );
Branch: 1 branch
BranchTrueFalseTotal
$grid_line == 0 ? : 1 1 2
195 9 };
196 58 ▶ my $corner = sub ( $boundary, $grid_line ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
197 58 my %arms = (
198 up => $vertical_arm->( $boundary - 1, $grid_line ),
199 down => $vertical_arm->( $boundary, $grid_line ),
200 left => $horizontal_arm->( $boundary, $grid_line - 1 ),
201 right => $horizontal_arm->( $boundary, $grid_line ),
202 );
203 58 my ( $on_frame, $frame_glyph ) = $frame_point->( $boundary, $grid_line, \%arms );
204 58 ▶ return $frame_glyph if $on_frame;
Branch: 1 branch
BranchTrueFalseTotal
if $on_frame 12 46 58
205 46 ▶ return Term::Fabulous::Enum::BorderStyle->junction(%arms) // ' ';
Condition50%1/2
"Term::Fabulous::Enum::BorderStyle"->junction(%arms) // " "
l!l
460
MC/DC0%0/1
"Term::Fabulous::Enum::BorderStyle"->junction(%arms) // " "
"Term::Fabulous::Enum::BorderStyle"->junction(%arms)
Truth table50%1/2
A
A= "Term::Fabulous::Enum::BorderStyle"->junction(%arms)
Aresult
11
00
206 9 };
207 114 ▶ my $side_style = sub ( $exists, $style ) {
Subroutine __ANON__: called CC=3 SCAR=11.1
208 114 ▶ return undef unless $exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 18 96 114
209 96 ▶ return $style // $BLANK;
Condition66%2/3
$style // $BLANK
l!l&&r!l&&!r
9420
MC/DC0%0/2
$style // $BLANK
$style $BLANK
Truth table66%2/3
A // B
A= $styleB= $BLANK
ABresult
1X1
011
000
210 9 };
211  
212 # The strips of the scrollbar column, beside the header lines, the
213 # body and the last line: each draws the frame's right side, in the
214 # table's style, and the horizontal lines that run on beside it (the
215 # top and the line below the header, the bottom). The side the body
216 # strip shares with the header and footer strips is one unbroken
217 # line, so its ends are arms of their corners.
218 1 ▶ my $strips = sub () {
Subroutine __ANON__: called CC=8 SCAR=23.1
219 1 my $right = _first_style( [ $table->{border_right} ] );
220 1 ▶ my $side = sub ($boundary) { $side_style->( $row_line_exists[$boundary], $h_gutter[$boundary] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
221 3 ▶ my $corner = sub ( $boundary, %arms ) {
Subroutine __ANON__: called CC=3 SCAR=11.7
222 3 my ( $on_frame, $frame_glyph ) = $frame_point->( $boundary, $columns, \%arms );
223 3 ▶ return $frame_glyph if $on_frame;
Branch: 1 branch
BranchTrueFalseTotal
if $on_frame 0 3 3
224 3 ▶ return Term::Fabulous::Enum::BorderStyle->junction(%arms) // ' ';
Condition50%1/2
"Term::Fabulous::Enum::BorderStyle"->junction(%arms) // " "
l!l
30
MC/DC0%0/1
"Term::Fabulous::Enum::BorderStyle"->junction(%arms) // " "
"Term::Fabulous::Enum::BorderStyle"->junction(%arms)
Truth table50%1/2
A
A= "Term::Fabulous::Enum::BorderStyle"->junction(%arms)
Aresult
11
00
225 1 };
226 3 ▶ my $strip = sub ( $sides, $corners, @frame_sides ) {
Subroutine __ANON__: called CC=2 SCAR=7.0
227 3 my %drawn = map { $_ => $sides->{$_} } grep { defined $sides->{$_} } keys %$sides;
228 3 my %corners = map { $_ => $corners->{$_} } grep { defined $corners->{$_} } keys %$corners;
229 3 ▶ my @outer = grep { defined $drawn{$_} && _drawn_outside( $drawn{$_}, $_ ) } @frame_sides;
Condition33%1/3
defined $drawn{$_} && _drawn_outside($drawn{$_}, $_)
!ll&&!rl&&r
005
MC/DC0%0/2
defined $drawn{$_} && _drawn_outside($drawn{$_}, $_)
defined $drawn{$_} _drawn_outside($drawn{$_}, $_)
Truth table33%1/3
A && B
A= defined $drawn{$_}B= _drawn_outside($drawn{$_}, $_)
ABresult
0X0
100
111
230 3 return { sides => \%drawn, corners => \%corners, outer => \@outer };
231 1 };
232 1 ▶ my %header = ( top => $side->(0), bottom => ( $header_lines ? $side->($header_lines) : undef ), right => $right );
Branch: 1 branch
BranchTrueFalseTotal
$header_lines ? : 1 0 1
233 1 my %footer = ( bottom => $side->($line_count), right => $right );
234 return {
235 header => $strip->(
236 \%header,
237 {
238 top_right => ( $header{top} && $header{right} ? $corner->( 0, left => $h_gutter[0], down => $right ) : undef ),
239 bottom_right => ( $header{bottom} && $header{right} ? $corner->( $header_lines, left => $h_gutter[$header_lines], up => $right, down => $right ) : undef ),
240 },
241 qw(top right)
242 ),
243 body => $strip->( { right => $right }, {}, qw(right) ),
244 footer =>
245 1 ▶ $strip->( \%footer, { bottom_right => ( $footer{bottom} && $footer{right} ? $corner->( $line_count, left => $h_gutter[$line_count], up => $right ) : undef ) }, qw(bottom right) ),
Branch: 3 branches
BranchTrueFalseTotal
$header{'top'} && $header{'right'} ? : 1 0 1
$header{'bottom'} && $header{'right'} ? : 1 0 1
$footer{'bottom'} && $footer{'right'} ? : 1 0 1
Condition33%3/9
$header{"top"} and $header{"right"}
!ll&&!rl&&r
001
$header{"bottom"} and $header{"right"}
!ll&&!rl&&r
001
$footer{"bottom"} and $footer{"right"}
!ll&&!rl&&r
001
MC/DC0%0/2
$header{"top"} and $header{"right"}
$header{"top"} $header{"right"}
MC/DC0%0/2
$header{"bottom"} and $header{"right"}
$header{"bottom"} $header{"right"}
MC/DC0%0/2
$footer{"bottom"} and $footer{"right"}
$footer{"bottom"} $footer{"right"}
Truth table33%1/3
A and B
A= $header{"top"}B= $header{"right"}
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $header{"bottom"}B= $header{"right"}
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $footer{"bottom"}B= $footer{"right"}
ABresult
0X0
100
111
246 };
247 9 };
248  
249 9 my @result;
250 9 foreach my $line ( 0 .. $last_line ) {
251 24 my $spanning = $lines->[$line]{spanning};
252 24 ▶ my @cell_columns = $spanning ? ( [ 0, $columns - 1 ] ) : map { [ $_, $_ ] } 0 .. $columns - 1;
Branch: 1 branch
BranchTrueFalseTotal
$spanning ? : 1 23 24
253 24 ▶ my $top_drawn = $row_line_exists[$line] && !$drawn_as_bottom->($line);
Condition100%3/3
$row_line_exists[$line] && !&$drawn_as_bottom($line)
!ll&&!rl&&r
9411
MC/DC100%2/2
$row_line_exists[$line] && !&$drawn_as_bottom($line)
$row_line_exists[$line] !&$drawn_as_bottom($line)
Truth table100%3/3
A && not(B)
A= $row_line_exists[$line]B= !&$drawn_as_bottom($line)
ABresult
0X0
100
111
254 24 ▶ my $bottom_drawn = $row_line_exists[ $line + 1 ] && $drawn_as_bottom->( $line + 1 );
Condition100%3/3
$row_line_exists[$line + 1] && &$drawn_as_bottom($line + 1)
!ll&&!rl&&r
9411
MC/DC100%2/2
$row_line_exists[$line + 1] && &$drawn_as_bottom($line + 1)
$row_line_exists[$line + 1] &$drawn_as_bottom($line + 1)
Truth table100%3/3
A && B
A= $row_line_exists[$line + 1]B= &$drawn_as_bottom($line + 1)
ABresult
0X0
100
111
255 24 my @cells;
256 24 foreach my $span (@cell_columns) {
257 47 my ( $first, $last ) = @$span;
258 my %sides = (
259 left => $side_style->( $column_line_exists[$first], $v[$line][$first] ),
260 right => ( $last == $columns - 1 ? $side_style->( $column_line_exists[$columns], $v[$line][$columns] ) : undef ),
261 20 ▶ top => ( $top_drawn ? $side_style->( 1, first { defined } @{ $h[$line] }[ $first .. $last ] ) : undef ),
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$bottom_drawn ? : 20 27 47
262 47 ▶ bottom => ( $bottom_drawn ? $side_style->( 1, first { defined } @{ $h[ $line + 1 ] }[ $first .. $last ] ) : undef ),
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
$last == $columns - 1 ? : 24 23 47
$top_drawn ? : 20 27 47
263 );
264 47 my %corners;
265 47 ▶ $corners{top_left} = $corner->( $line, $first ) if $sides{top} && $sides{left};
Branch: 1 branch
BranchTrueFalseTotal
if $sides{"top"} and $sides{"left"} 20 27 47
Condition66%2/3
$sides{"top"} and $sides{"left"}
!ll&&!rl&&r
27020
MC/DC50%1/2
$sides{"top"} and $sides{"left"}
$sides{"top"} $sides{"left"}
Truth table66%2/3
A and B
A= $sides{"top"}B= $sides{"left"}
ABresult
0X0
100
111
266 47 ▶ $corners{top_right} = $corner->( $line, $columns ) if $sides{top} && $sides{right};
Branch: 1 branch
BranchTrueFalseTotal
if $sides{"top"} and $sides{"right"} 9 38 47
Condition100%3/3
$sides{"top"} and $sides{"right"}
!ll&&!rl&&r
27119
MC/DC100%2/2
$sides{"top"} and $sides{"right"}
$sides{"top"} $sides{"right"}
Truth table100%3/3
A and B
A= $sides{"top"}B= $sides{"right"}
ABresult
0X0
100
111
267 47 ▶ $corners{bottom_left} = $corner->( $line + 1, $first ) if $sides{bottom} && $sides{left};
Branch: 1 branch
BranchTrueFalseTotal
if $sides{"bottom"} and $sides{"left"} 20 27 47
Condition66%2/3
$sides{"bottom"} and $sides{"left"}
!ll&&!rl&&r
27020
MC/DC50%1/2
$sides{"bottom"} and $sides{"left"}
$sides{"bottom"} $sides{"left"}
Truth table66%2/3
A and B
A= $sides{"bottom"}B= $sides{"left"}
ABresult
0X0
100
111
268 47 ▶ $corners{bottom_right} = $corner->( $line + 1, $columns ) if $sides{bottom} && $sides{right};
Branch: 1 branch
BranchTrueFalseTotal
if $sides{"bottom"} and $sides{"right"} 9 38 47
Condition100%3/3
$sides{"bottom"} and $sides{"right"}
!ll&&!rl&&r
27119
MC/DC100%2/2
$sides{"bottom"} and $sides{"right"}
$sides{"bottom"} $sides{"right"}
Truth table100%3/3
A and B
A= $sides{"bottom"}B= $sides{"right"}
ABresult
0X0
100
111
269 47 delete @corners{ grep { !defined $corners{$_} } keys %corners };
270 47 my %on_frame = (
271 left => $first == 0,
272 right => $last == $columns - 1,
273 top => $line == 0,
274 bottom => $line == $last_line,
275 );
276 47 ▶ my @outer = grep { defined $sides{$_} && $on_frame{$_} && _drawn_outside( $sides{$_}, $_ ) } qw(left right top bottom);
Condition100%6/6
defined $sides{$_} && $on_frame{$_} && _drawn_outside($sides{$_}, $_)
!ll&&!rl&&r
128852
defined $sides{$_} and $on_frame{$_}
!ll&&!rl&&r
953360
MC/DC100%3/3
defined $sides{$_} && $on_frame{$_} && _drawn_outside($sides{$_}, $_)
defined $sides{$_} $on_frame{$_} _drawn_outside($sides{$_}, $_)
Truth table100%4/4
A and B && C
A= defined $sides{$_}B= $on_frame{$_}C= _drawn_outside($sides{$_}, $_)
ABCresult
0XX0
10X0
1100
1111
277 47 push @cells, { sides => { map { $_ => $sides{$_} } grep { defined $sides{$_} } keys %sides }, corners => \%corners, outer => \@outer };
278 }
279 24 push @result, \@cells;
280 }
281 9 ▶ return { lines => \@result, gutter => $gutter ? $strips->() : undef };
Branch: 1 branch
BranchTrueFalseTotal
$gutter ? : 1 8 9
282 }
283  
284 1 1;
285  
286 __END__
« blib/lib/Term/Fabulous/Render/Target/Mask.pm ↑ Summary blib/lib/Term/Fabulous/Chart/Marker.pm »