| 1 | 3 | ▶ | strict; use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use v5.20; # signatures | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | no warnings "experimental::lexical_subs"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use feature qw/say state lexical_subs/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | # vi:set ai expandtab ts=4: | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | # Based on code in the Text::Table documentation and | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # https://stackoverflow.com/questions/30762521/how-can-i-print-a-table-with-multi-line-strings-using-the-texttable-module | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | package Text::Table::Boxed; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | require Text::Table; # old versions of 'base' don't auto-require? | |||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use base 'Text::Table'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | { no strict 'refs'; ${__PACKAGE__."::VER"."SION"} = 997.999; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | our $VERSION = '1.003'; # VERSION from Dist::Zilla::Plugin::OurPkgVersion | |||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | our $DATE = '2024-12-14'; # DATE from Dist::Zilla::Plugin::OurDate | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use List::Util qw/min max first all any/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use List::MoreUtils qw/true false none firstidx/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | bool => sub { return 1; }, # Don't stringify just for a boolean test | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | '""' => 'rendered_stringify', | |||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | use Data::Dumper::Interp 7.010 qw/visnew ivis dvis vis avis u/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | use warnings::register; # creates category name same as __PACKAGE__ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub btw { goto &Data::Dumper::Interp::btw } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
btw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub btwN { goto &Data::Dumper::Interp::btwN } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
btwN: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub oops { @_ = ("OOPS:",@_); goto &Carp::confess } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oops: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | our $debug = 0; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | our %builtin_pictures = ( | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | ascii => <<'EOF', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | +-------+ | ||||||||||||||||||||||||||||||||||||||||||
| 43 | | c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 44 | +=======+ | ||||||||||||||||||||||||||||||||||||||||||
| 45 | | c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 46 | +---+---+ | ||||||||||||||||||||||||||||||||||||||||||
| 47 | | c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 48 | +-------+ | ||||||||||||||||||||||||||||||||||||||||||
| 49 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | boxrule => <<'EOF', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ┌───┬───┐ | ||||||||||||||||||||||||||||||||||||||||||
| 53 | │ c │ c │ | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ╞═══╪═══╡ | ||||||||||||||||||||||||||||||||||||||||||
| 55 | │ c │ c │ | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ├───┼───┤ | ||||||||||||||||||||||||||||||||||||||||||
| 57 | │ c │ c │ | ||||||||||||||||||||||||||||||||||||||||||
| 58 | └───┴───┘ | ||||||||||||||||||||||||||||||||||||||||||
| 59 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | outerbox => <<'EOF', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ┌─────┐ | ||||||||||||||||||||||||||||||||||||||||||
| 63 | │ c c │ | ||||||||||||||||||||||||||||||||||||||||||
| 64 | │ c c │ | ||||||||||||||||||||||||||||||||||||||||||
| 65 | │ c c │ | ||||||||||||||||||||||||||||||||||||||||||
| 66 | └─────┘ | ||||||||||||||||||||||||||||||||||||||||||
| 67 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 69 | ▶ | sub _handle_rulepicture($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_rulepicture: called CC=35 SCAR=37.7
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 69 | my $opts = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 69 | ▶ | $opts->{CONTENT_CHAR} //= 'c'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$opts{"CONTENT_CHAR"} //= "c"
MC/DC0%0/1
$$opts{"CONTENT_CHAR"} //= "c"
$$opts{"CONTENT_CHAR"}
Truth table50%1/2
A
A= $$opts{"CONTENT_CHAR"}
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Get separate line strings sans final newline | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 69 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 69 | ▶ | if (ref($opts->{picture}) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 63 | @lines = @{ $opts->{picture} }; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 63 | foreach(@lines) { s/\R\z//; } | |||||||||||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | ▶ | @lines = split /\R/, ($opts->{picture} // oops); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$opts{"picture"} // oops()
MC/DC0%0/2
$$opts{"picture"} // oops()
$$opts{"picture"}
oops()
Truth table33%1/3
A // B
A= $$opts{"picture"}B= oops()
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($debug) { btw "--- INPUT PICRURE ---\n",(map{ "$_\n" } @lines),"---(end)---\n"; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 69 | ▶ | croak "The 'picture' contains only ",scalar(@lines)," line.\n", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | "Please provide two or more lines either as an array\n", | ||||||||||||||||||||||||||||||||||||||||||
| 88 | " [\"line1\", \"line2\", ... ]\n", | ||||||||||||||||||||||||||||||||||||||||||
| 89 | "or a plain multi-line string\n", | ||||||||||||||||||||||||||||||||||||||||||
| 90 | " \"line1\\nline2\\n...\"\n" | ||||||||||||||||||||||||||||||||||||||||||
| 91 | if @lines < 2; | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1164 | ▶ | my sub _is_sepspec($) { $_[0] =~ /$opts->{CONTENT_CHAR}/ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_sepspec: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1164 | ▶ | my sub _is_rule($) { ! _is_sepspec($_[0]) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_rule: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 69 | my $first_rulespec; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 359 | ▶ | my sub _push_rule($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_push_rule: called CC=6 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 359 | my ($aref, $spec) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 359 | ▶ | croak "Rule lines must have the same length\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$first_rulespec //= $spec
MC/DC0%0/2
$first_rulespec //= $spec
$first_rulespec
$spec
Truth table66%2/3
A //= B
A= $first_rulespecB= $spec
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | unless length($first_rulespec//=$spec) == length($spec); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 359 | state $warned_once; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 359 | ▶ | if ($spec =~ /( [a-z] )/ && !$warned_once++ && warnings::enabled()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$spec =~ /( [a-z] )/u and not $warned_once++ and warnings::enabled()
$spec =~ /( [a-z] )/u and not $warned_once++
MC/DC0%0/3
$spec =~ /( [a-z] )/u and not $warned_once++ and warnings::enabled()
$spec =~ /( [a-z] )/u
not $warned_once++
warnings::enabled()
Truth table25%1/4
A and not(B) and C
A= $spec =~ /( [a-z] )/uB= not $warned_once++C= warnings::enabled()
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | carp "A rule line contains an isolated letter '$1' which is not the letter '$opts->{CONTENT_CHAR}' used as a stand-in for cell content. Was '$opts->{CONTENT_CHAR}' intended?\n"; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 359 | push @$aref, $spec; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 69 | my (@top_rule, @mid_rule, @bot_rule); | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # Collect all rule strings (will later be split into segments) | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 69 | ▶ | if (_is_rule($lines[-1])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 69 | _push_rule(\@bot_rule, pop @lines); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 69 | ▶ | if (_is_rule($lines[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 69 | _push_rule(\@top_rule, shift @lines); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 69 | ▶ | croak "There must be at least one 'data line' in the picture\n" unless @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 69 | foreach (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 118 | 513 | ▶ | _push_rule(\@mid_rule, $_) if _is_rule($_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 69 | my ($sepspec_line, @sepsegs); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 69 | foreach (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 123 | 513 | ▶ | next if _is_rule($_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 292 | ▶ | if (defined $sepspec_line) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 223 | ▶ | croak "All separator-sepc lines in the picture must be identical\n", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | "(Text::Table does not support different seps in different rows)\n" | ||||||||||||||||||||||||||||||||||||||||||
| 128 | unless $_ eq $sepspec_line; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 69 | $sepspec_line = $_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | # Isolate separators and content-standin-chars | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # e.g. ("| ", 'c', " | ", 'c', " |") | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # or ("", 'c', " | ", 'c', "" ) if no edge-separators | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 69 | pos=undef; | |||||||||||||||||||||||||||||||||||||||||
| 135 | # split will provide the empty ("") segment we want where there is no | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # edge separator (that, if CONTENT_CHAR is the first or last char). | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # Note that the CONTENT_CHAR is in a (capture group) so is included | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # as an element in the resultin list. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 69 | @sepsegs = split /($opts->{CONTENT_CHAR})/, $_, -1; | |||||||||||||||||||||||||||||||||||||||||
| 140 | # Split rule strings at the same positions | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 69 | foreach (@top_rule, @mid_rule, @bot_rule) { | |||||||||||||||||||||||||||||||||||||||||
| 142 | 359 | my @rulesegs; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 359 | ▶ | for (my $off=0, my $ix=0; $ix <= $#sepsegs; ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 3813 | push @rulesegs, substr($_, $off, length($sepsegs[$ix])); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 3813 | $off += length($sepsegs[$ix]); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 3813 | ++$ix; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 359 | $_ = \@rulesegs; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # Now rules are represented as [ list of substrings ] | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # and "data" rows (which must be identical) similarly in @sepsegs | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 69 | ▶ | oops unless all{ scalar(@$_) == @sepsegs } @top_rule, @mid_rule, @bot_rule; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 69 | my $num_cols = @{ $opts->{columns} }; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 69 | my $pic_cols = int(@sepsegs/2); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 69 | ▶ | btw dvis 'BEFORE PIC-LEN-ADJ: $num_cols $pic_cols @sepsegs\n@top_rule\n@mid_rule\n@bot_rule' if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | # Replicate the last picture column if the actual data is wider | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # Delete the last picture column if the actual data is narrower | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 69 | ▶ | while ($num_cols != $pic_cols) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | # ("|-", '-', "+++", '+', "-|") # a rule | ||||||||||||||||||||||||||||||||||||||||||
| 163 | # ("| ", 'c', " | ", 'c', " |") # sepsegs | ||||||||||||||||||||||||||||||||||||||||||
| 164 | # ^^^^^^^^^^ #replicate or delete these | ||||||||||||||||||||||||||||||||||||||||||
| 165 | # $#-2 $#-1 $# | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 92 | ▶ | if ($pic_cols < $num_cols) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 24 | ▶ | croak "Picture must have at least two columns\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | if $pic_cols < 2; # no separator to replicate | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 24 | foreach (\@sepsegs, @top_rule, @mid_rule, @bot_rule) { | |||||||||||||||||||||||||||||||||||||||||
| 170 | 160 | splice @$_, $#$_, 0, @$_[$#$_-2..$#$_-1]; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 24 | ++$pic_cols; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 68 | foreach (\@sepsegs, @top_rule, @mid_rule, @bot_rule) { | |||||||||||||||||||||||||||||||||||||||||
| 175 | 436 | splice @$_, $#$_-2, 2 | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 68 | --$pic_cols; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 69 | ▶ | btw dvis 'AFTER PIC-LEN-ADJ: @sepsegs\n@top_rule\n@mid_rule\n@bot_rule' if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | # Insert the separators among the column titles | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # The last separator always goes on the right edge (possibly ""). | ||||||||||||||||||||||||||||||||||||||||||
| 185 | my @withseps = map{ | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 271 | ▶ | ( \( $sepsegs[$_*2] // oops ), $opts->{columns}->[$_] ) | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$sepsegs[$_ * 2] // oops()
MC/DC0%0/2
$sepsegs[$_ * 2] // oops()
$sepsegs[$_ * 2]
oops()
Truth table33%1/3
A // B
A= $sepsegs[$_ * 2]B= oops()
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 69 | } 0..$#{$opts->{columns}}; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 69 | push @withseps, \$sepsegs[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | # RULE GENERATORS | ||||||||||||||||||||||||||||||||||||||||||
| 191 | # Each rule generator uses a pair of callbacks, herein called the "field" | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # and "separator" callbacks, Each provides characters to put into a rule | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # line which will be under/over a field or separator string, respectively. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # The arguments to the callback are ($index, $num_chars). | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # For the "field callback", $index counts *fields*. | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # For the "separator callback", $index is not useful due to this bug: | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # https://github.com/shlomif/Text-Table/issues/14 . | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # However the callbacks step through all the characters in the separators | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # left-to-right (sometimes multiple characters at once), so a state variable | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # can be used to know the next horizontal position. $index is used | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # only to recognize the initial call ($index==0) and reset the state. | ||||||||||||||||||||||||||||||||||||||||||
| 204 | # | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 69 | for my $key (qw/top_rule mid_rule bot_rule/) { | |||||||||||||||||||||||||||||||||||||||||
| 206 | 207 | $opts->{$key} = []; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 207 | ▶ | foreach my $rule_segs (eval "\@$key") { die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | # Rule and "data" lines in the picture have been split into arrays | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # of pieces corresponding to separators and CONTENT_CHAR characters. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # A "field" rule segment is recognizable because the corresponding | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # element in @sepsegs is the CONTENT_CHAR. | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 359 | my $field_chars = ""; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 359 | my $sep_chars = ""; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 359 | ▶ | oops unless @$rule_segs == @sepsegs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 359 | for my $ix (0..$#$rule_segs) { | |||||||||||||||||||||||||||||||||||||||||
| 216 | 3349 | ▶ | if ($sepsegs[$ix] eq $opts->{CONTENT_CHAR}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 1495 | $field_chars .= $rule_segs->[$ix]; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 1854 | $sep_chars .= $rule_segs->[$ix]; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 359 | ▶ | btw dvis 'xxxx $key $field_chars $sep_chars $rule_segs @sepsegs\n @withseps' if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 359 | ▶ | oops unless length($field_chars) == $num_cols; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 878 | ▶ | my $field_callback = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 878 | my ($index, $len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 878 | my $char = substr($field_chars,$index,1); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 878 | my $str = $char x $len; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 878 | ▶ | warn "-fld- [$index] len=$len returning '$str'\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 878 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 359 | }; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 2825 | ▶ | my $separator_callback = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 2825 | my ($index, $len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 2825 | state $char_ix; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 2825 | ▶ | $char_ix = 0 if $index==0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 2825 | my $str = substr($sep_chars, $char_ix, $len); | |||||||||||||||||||||||||||||||||||||||||
| 236 | 2825 | $char_ix += $len; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 2825 | ▶ | warn "=SEP= [$index] len=$len returning '$str'\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 2825 | ▶ | oops dvis '$sep_chars $index $len $str $char_ix' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | unless length($str) == $len; | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 2825 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 359 | }; | |||||||||||||||||||||||||||||||||||||||||
| 242 | # Save the subrefs and debug info | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 359 | push @{ $opts->{$key} }, { | |||||||||||||||||||||||||||||||||||||||||
| 244 | sub1 => $field_callback, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | sub2 => $separator_callback, | ||||||||||||||||||||||||||||||||||||||||||
| 246 | sep_chars => $sep_chars, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | field_chars => $field_chars, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 69 | $opts->{withseps} = \@withseps; | |||||||||||||||||||||||||||||||||||||||||
| 252 | }#_handle_rulepicture | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 3 | ▶ | use constant MYKEY => "_key_".__PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 69 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 69 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 257 | my %opts = (@_==1 && ref($_[0]) eq "HASH" && exists($_[0]->{columns})) | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 69 | ▶ | ? %{ shift(@_) } # new API | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@_ == 1 and ref $_[0] eq "HASH" and exists $_[0]{"columns"}
@_ == 1 and ref $_[0] eq "HASH"
MC/DC33%1/3
@_ == 1 and ref $_[0] eq "HASH" and exists $_[0]{"columns"}
@_ == 1
ref $_[0] eq "HASH"
exists $_[0]{"columns"}
Truth table50%2/4
A and B and C
A= @_ == 1B= ref $_[0] eq "HASH"C= exists $_[0]{"columns"}
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | : ( columns => [@_] ); # old API | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 69 | foreach (keys %opts) { | |||||||||||||||||||||||||||||||||||||||||
| 262 | 137 | ▶ | croak "Invalid option key '$_'\n" unless /^(?:columns|picture|style)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | croak "'columns' must be provided in OPTIONS\n" | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 69 | ▶ | unless defined ($opts{columns}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | croak "'columns' must be an array ref\n" | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 69 | ▶ | unless reftype($opts{columns}) eq "ARRAY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 69 | ▶ | $opts{picture} //= $builtin_pictures{ascii}; # the default | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{"picture"} //= $Text::Table::Boxed::builtin_pictures{"ascii"}
MC/DC0%0/2
$opts{"picture"} //= $Text::Table::Boxed::builtin_pictures{"ascii"}
$opts{"picture"}
$Text::Table::Boxed::builtin_pictures{"ascii"}
Truth table66%2/3
A //= B
A= $opts{"picture"}B= $Text::Table::Boxed::builtin_pictures{"ascii"}
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 69 | ▶ | if (defined $opts{style}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | $opts{picture} = $builtin_pictures{ $opts{style} } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | ▶ | // croak "Invalid 'style' \"$opts{style}\"\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Text::Table::Boxed::builtin_pictures{$opts{"style"}} // croak(qq[Invalid 'style' "$opts{"style"}"\n])
MC/DC0%0/1
$Text::Table::Boxed::builtin_pictures{$opts{"style"}} // croak(qq[Invalid 'style' "$opts{"style"}"\n])
$Text::Table::Boxed::builtin_pictures{$opts{"style"}}
Truth table50%1/2
A
A= $Text::Table::Boxed::builtin_pictures{$opts{"style"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | delete $opts{CONTENT_CHAR}; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | # Parse the picture. | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # Creates {withseps} and {rule_generators} in %opts | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 69 | _handle_rulepicture(\%opts); | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 69 | my $self = Text::Table::new(__PACKAGE__, @{ $opts{withseps} }); | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 69 | $opts{row_starts} = [ 0 ]; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 69 | $opts{next_rx} = $self->title_height; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 69 | $self->{MYKEY()} = \%opts; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 69 | $self | |||||||||||||||||||||||||||||||||||||||||
| 289 | }#new | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 235 | ▶ | sub _TTBrule { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_TTBrule: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 235 | my ($key, $self, $ix) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 235 | ▶ | $ix //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ix //= 0
MC/DC100%1/1
$ix //= 0
$ix
Truth table100%2/2
A
A= $ix
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | return undef | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 235 | ▶ | unless my $list = $self->{MYKEY()}->{"${key}_rule"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 235 | ▶ | $list = [ $list ] unless ref($list) eq "ARRAY"; # [ {...}, ... ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | return undef | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 235 | ▶ | if $#$list == -1; # _no_ mid rules at all | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | # If asking for a higher index than exists, re-use the last one. | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # This is appropriate for multiple mid_rules. | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 229 | ▶ | my $h = $ix > $#$list ? $list->[-1] : $list->[$ix]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 229 | my $r = $self->rule($h->{sub1}, $h->{sub2}); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 229 | $r | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 71 | ▶ | sub top_rule { _TTBrule("top", @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
top_rule: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 92 | ▶ | sub mid_rule { _TTBrule("mid", @_) } # takes optional index argument | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mid_rule: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 72 | ▶ | sub bot_rule { _TTBrule("bot", @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bot_rule: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 67 | ▶ | sub num_rows { scalar @{ $_[0]->{MYKEY()}->{row_starts} } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num_rows: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 4 | ▶ | sub num_body_rows { $_[0]->num_rows() - 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num_body_rows: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 66 | ▶ | sub rendered_table_height { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_table_height: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 66 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 66 | my $opts = $self->{MYKEY()}; | |||||||||||||||||||||||||||||||||||||||||
| 317 | return( | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 66 | ▶ | scalar(@{$opts->{top_rule}}) # 1 or 0 if no top rule | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | + $self->table_height() # data lines | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | # Rules after rows. | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # All but the last row are followed by a mid_rule, iff defined. | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # The last row is followed by bot_rule, iff defined. | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 66 | + (@{$opts->{mid_rule}} ? ($self->num_rows-1) : 0) | |||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 66 | + scalar(@{$opts->{bot_rule}}) # 1 or 0 if no bot rule | |||||||||||||||||||||||||||||||||||||||||
| 328 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 91 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 91 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 91 | my $opts = $self->{MYKEY()}; | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | # Calculate height of the row, taking into account embedded newlines | ||||||||||||||||||||||||||||||||||||||||||
| 336 | # (which Text::Table will split, inserting multiple lines) | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 91 | my $height = 1; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 91 | foreach (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 339 | 340 | $height += scalar(@{[ /\R/g ]}); | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 91 | push @{ $opts->{row_starts} }, $self->table_height; | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 91 | $self->SUPER::add(@_); | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 5 | ▶ | sub rendered_title { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_title: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 5 | ▶ | my @lines = grep{defined} | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->mid_rule(0) // $self->bot_rule
MC/DC0%0/2
$self->mid_rule(0) // $self->bot_rule
$self->mid_rule(0)
$self->bot_rule
Truth table66%2/3
A // B
A= $self->mid_rule(0)B= $self->bot_rule
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | $self->top_rule(), | ||||||||||||||||||||||||||||||||||||||||||
| 350 | $self->title(), | ||||||||||||||||||||||||||||||||||||||||||
| 351 | ($self->mid_rule(0)//$self->bot_rule()) | ||||||||||||||||||||||||||||||||||||||||||
| 352 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 5 | ▶ | return (wantarray ? @lines : join("", @lines)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 85 | ▶ | sub rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: called CC=15 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 85 | my ($self, $row_index, $num_rows, $_with_rules) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 85 | ▶ | $row_index //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$row_index //= 0
MC/DC0%0/1
$row_index //= 0
$row_index
Truth table50%1/2
A
A= $row_index
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 85 | ▶ | $num_rows //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$num_rows //= 1
MC/DC0%0/1
$num_rows //= 1
$num_rows
Truth table50%1/2
A
A= $num_rows
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 85 | my $opts = $self->{MYKEY()}; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 85 | my $row_starts = $opts->{row_starts}; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 85 | ▶ | croak "Negative index not supported\n" if $row_index < 0 or $num_rows < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$row_index < 0 or $num_rows < 0
MC/DC0%0/2
$row_index < 0 or $num_rows < 0
$row_index < 0
$num_rows < 0
Truth table33%1/3
A or B
A= $row_index < 0B= $num_rows < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 85 | my $max_rx = $#{ $row_starts }; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 85 | ▶ | croak "Row index out of range\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | if $row_index+$num_rows-1 > $max_rx; | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | my @results = map{ | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 85 | my $first_lx = $row_starts->[$_]; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 161 | ▶ | my $nextrow_first_lx = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | ($_ == $max_rx ? $self->height() : $row_starts->[$_+1]); | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 161 | my $num_lines = $nextrow_first_lx - $first_lx; | |||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 161 | my @lines = $self->table($first_lx, $num_lines); | |||||||||||||||||||||||||||||||||||||||||
| 374 | 161 | ▶ | if ($_with_rules) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 157 | ▶ | if ($_ == 0 && defined(my $str = $self->top_rule())) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ == 0 and defined(my $str = $self->top_rule)
MC/DC50%1/2
$_ == 0 and defined(my $str = $self->top_rule)
$_ == 0
defined(my $str = $self->top_rule)
Truth table66%2/3
A and B
A= $_ == 0B= defined(my $str = $self->top_rule)
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 65 | unshift @lines, $str; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 157 | ▶ | if (defined(my $str = $_==$max_rx ? $self->bot_rule() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | : $self->mid_rule($_))) { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 152 | push @lines, $str; | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 161 | [ @lines ] | |||||||||||||||||||||||||||||||||||||||||
| 384 | } $row_index..$row_index+$num_rows-1; | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 85 | ▶ | btw dvis '##ROWS($row_index $num_rows $_with_rules) $max_rx --> @results' if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 85 | ▶ | if (wantarray) { return @results; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 16 | ▶ | croak "Scalar context but multiple rows in results\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | if @results > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 16 | return $results[0]; | |||||||||||||||||||||||||||||||||||||||||
| 391 | }#rows | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 18 | ▶ | sub body_rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_rows: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 18 | my ($self, $row_index, $num_rows, $_with_rules) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 18 | $self->rows($row_index+1, $num_rows, $_with_rules); | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 17 | ▶ | sub rendered_body_rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_body_rows: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 17 | my ($self, $row_index, $num_rows) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 17 | return $self->body_rows($row_index, $num_rows, 1); | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | sub title_row { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
title_row: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | my ($self, $_with_rules) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return $self->body_rows(0, 1, $_with_rules); | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | sub rendered_title_row { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_title_row: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | return $self->title_row(1); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | ▶ | sub rendered_title_height() { $_[0]->title_height() + 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_title_height: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 65 | ▶ | sub rendered_rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_rows: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 65 | my ($self, $row_index, $num_rows) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 65 | return $self->rows($row_index, $num_rows, 1); | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 65 | ▶ | sub rendered_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_table: called CC=12 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 65 | my ($self, $start_lx, $num_lines) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 65 | my $opts = $self->{MYKEY()}; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 65 | my $row_starts = $opts->{row_starts}; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 65 | my $max_lx = $self->rendered_table_height() - 1; | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 65 | ▶ | $num_lines //= ($max_lx + 1); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$num_lines //= $max_lx + 1
MC/DC0%0/1
$num_lines //= $max_lx + 1
$num_lines
Truth table50%1/2
A
A= $num_lines
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 65 | ▶ | $start_lx //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$start_lx //= 0
MC/DC0%0/1
$start_lx //= 0
$start_lx
Truth table50%1/2
A
A= $start_lx
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 65 | ▶ | croak "Negative index not supported\n" if $start_lx < 0 or $num_lines < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$start_lx < 0 or $num_lines < 0
MC/DC0%0/2
$start_lx < 0 or $num_lines < 0
$start_lx < 0
$num_lines < 0
Truth table33%1/3
A or B
A= $start_lx < 0B= $num_lines < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 65 | my $last_lx = $start_lx + $num_lines - 1; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 65 | ▶ | croak "Line index $start_lx+$num_lines-1 is out of range (max=$max_lx)\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | if $last_lx > $max_lx; | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | # Retrieve rows and flatten result, truncating some lines if appropraite | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | my $last_rx = $last_lx >= $row_starts->[-1] | ||||||||||||||||||||||||||||||||||||||||||
| 435 | ? $#$row_starts | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | : first{ $last_lx >= $row_starts->[$_] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 65 | ▶ | reverse(0..$#$row_starts-1) ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 65 | ▶ | btw dvis 'REND($start_lx, $num_lines) $row_starts $max_lx $last_lx $last_rx' if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | my $first_rx = $start_lx >= $row_starts->[$last_rx] | ||||||||||||||||||||||||||||||||||||||||||
| 442 | ? $last_rx | ||||||||||||||||||||||||||||||||||||||||||
| 443 | #: first{ $start_lx < $row_starts->[$_+1] } 0..$last_rx-1 ; | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 63 | ▶ | : first{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | #btw '##INfirst last_rx=',vis($last_rx),' $_=',vis($_); | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 65 | ▶ | $start_lx < $row_starts->[$_+1] } 0..$last_rx-1 ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | my @lines = ( | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 65 | map{ @$_ } $self->rendered_rows($first_rx, $last_rx-$first_rx+1) | |||||||||||||||||||||||||||||||||||||||||
| 450 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 65 | ▶ | btw dvis '##REND.B $last_lx $start_lx $num_lines @lines' if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 65 | splice @lines, $last_lx-$start_lx+1; # trunc undesired lines from last row | |||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 65 | ▶ | btw dvis '##REND.C @lines' if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 65 | ▶ | return (wantarray ? @lines : join("", @lines)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | }#rendered_table | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | sub rendered_body { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_body: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my ($self, $start_lx, $num_lines) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 460 | return | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | $self->rendered_table( $start_lx + $self->rendered_title_height(), | |||||||||||||||||||||||||||||||||||||||||
| 462 | $num_lines ); | ||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 65 | ▶ | sub rendered_stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rendered_stringify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 65 | my $self = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 65 | return( scalar $self->rendered_table() ); | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | Text::Table::Boxed - Automate separators and rules for Text::Table | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | use Text::Table::Boxed; | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | my $tb = Text::Table::Boxed->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 483 | columns => [ "Planet", "Radius\nkm", "Density\ng/cm^3" ], | ||||||||||||||||||||||||||||||||||||||||||
| 484 | style => "boxrule", | ||||||||||||||||||||||||||||||||||||||||||
| 485 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | $tb->load( | ||||||||||||||||||||||||||||||||||||||||||
| 488 | [ "Mercury", 2360, 3.7 ], | ||||||||||||||||||||||||||||||||||||||||||
| 489 | [ "Venus", 6110, 5.1 ], | ||||||||||||||||||||||||||||||||||||||||||
| 490 | [ "Earth", 6378, 5.52 ], | ||||||||||||||||||||||||||||||||||||||||||
| 491 | [ "Jupiter", 71030, 1.3 ], | ||||||||||||||||||||||||||||||||||||||||||
| 492 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | print $tb; # Render table including separators and rules | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | # Custom rules and separators | ||||||||||||||||||||||||||||||||||||||||||
| 497 | my $tb = Text::Table::Boxed->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 498 | columns => [ "Planet", "Radius\nkm", "Density\ng/cm^3" ], | ||||||||||||||||||||||||||||||||||||||||||
| 499 | picture => <<'EOF', | ||||||||||||||||||||||||||||||||||||||||||
| 500 | ┌───╥───┬───┐ | ||||||||||||||||||||||||||||||||||||||||||
| 501 | │ c ║ c │ c │ | ||||||||||||||||||||||||||||||||||||||||||
| 502 | ╞═══╬═══╪═══╡ | ||||||||||||||||||||||||||||||||||||||||||
| 503 | │ c ║ c │ c │ | ||||||||||||||||||||||||||||||||||||||||||
| 504 | ├───╫───┼───┤ | ||||||||||||||||||||||||||||||||||||||||||
| 505 | │ c ║ c │ c │ | ||||||||||||||||||||||||||||||||||||||||||
| 506 | ╘═══╩═══╧═══╛ | ||||||||||||||||||||||||||||||||||||||||||
| 507 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 508 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | my @lines = $tb->rendered_title(); # including rules | ||||||||||||||||||||||||||||||||||||||||||
| 511 | my @lines = $tb->rendered_table(); # including rules | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | # Retrieve rows, each of which is an array of possibly-multiple lines, | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # the last of which is a rule line if appropriate. | ||||||||||||||||||||||||||||||||||||||||||
| 515 | my $lineset = $tb->rendered_title(); | ||||||||||||||||||||||||||||||||||||||||||
| 516 | my @linesets = $tb->rendered_body_rows($body_row_index, $num_rows); | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | This wrapper for L<Text::Table> automates column separators | ||||||||||||||||||||||||||||||||||||||||||
| 521 | and horizontal rules. Embedded newlines are allowed in cell data. | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | Support for ASCII or Unicode box-drawing characters is built in, | ||||||||||||||||||||||||||||||||||||||||||
| 524 | or you can give an "ascii art" picture showing what you want. | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | B<Text:Table::Boxed> is a derived class of Text::Table and supports all of | ||||||||||||||||||||||||||||||||||||||||||
| 527 | it's methods. | ||||||||||||||||||||||||||||||||||||||||||
| 528 | C<new> supports a different API where a single hashref argument supplies | ||||||||||||||||||||||||||||||||||||||||||
| 529 | column descriptors in a 'columns' element, along with possibly other options. | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | =head1 ROWS | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | The concept of "B<row>" is introduced, which represents a possibly-multiline | ||||||||||||||||||||||||||||||||||||||||||
| 534 | table row. Rules are inserted only at row boundaries, not between lines | ||||||||||||||||||||||||||||||||||||||||||
| 535 | within a row. Multi-line rows exist where cell values | ||||||||||||||||||||||||||||||||||||||||||
| 536 | contain embedded newlines. | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | Methods with "B<row>" in their name return lines segregated into rows, each | ||||||||||||||||||||||||||||||||||||||||||
| 539 | row represented by an array of the constituent lines. | ||||||||||||||||||||||||||||||||||||||||||
| 540 | In contrast, similar methods without "row" in their name return a flat | ||||||||||||||||||||||||||||||||||||||||||
| 541 | list of lines (or in scalar context, a single multiline string). | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | Methods with "B<rendered>" in their name include I<rule lines> in their | ||||||||||||||||||||||||||||||||||||||||||
| 544 | result. For example B<rendered_table()> returns all lines in the table | ||||||||||||||||||||||||||||||||||||||||||
| 545 | including rule lines, whereas B<table()> omits rule lines. | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | I<Rules> are inserted only when B<rendered_*()> methods are called, however | ||||||||||||||||||||||||||||||||||||||||||
| 548 | I<separators>, i.e. characters between columns and at the edges of data rows, | ||||||||||||||||||||||||||||||||||||||||||
| 549 | are always present because they | ||||||||||||||||||||||||||||||||||||||||||
| 550 | are inserted among the original columns by 'new' and exist in the | ||||||||||||||||||||||||||||||||||||||||||
| 551 | underlying L<Text::Table> object. | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | =item B<columns> => [ column titles... ] | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | A list of column titles or descriptor hashrefs, as documented in L<Text::Table>. | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | Separators should not be included here. | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | =item B<style> => "ascii" | "boxrule" | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | Use a built-in set of separator and rule characters. | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | =item B<picture> => "Multi\nLine\nString"; | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | =item B<picture> => [ lines ]; | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | Specify separator and rule-line characters using a picture of what you want | ||||||||||||||||||||||||||||||||||||||||||
| 572 | (see example in the SYNOPSIS). | ||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | The letter 'c' is a stand-in for cell content; all other characters in | ||||||||||||||||||||||||||||||||||||||||||
| 575 | "data" rows are taken as separators including spaces | ||||||||||||||||||||||||||||||||||||||||||
| 576 | (typically included for padding). | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | "Rule" lines should be exactly what would be displayed for a table | ||||||||||||||||||||||||||||||||||||||||||
| 579 | the same size as the picture. Portions are replicated as needed to fit | ||||||||||||||||||||||||||||||||||||||||||
| 580 | the actual table. | ||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | The picture must contain at least two columns; with more columns | ||||||||||||||||||||||||||||||||||||||||||
| 583 | different separators may be specified at various horizontal positions | ||||||||||||||||||||||||||||||||||||||||||
| 584 | (however the same separator must be used in every | ||||||||||||||||||||||||||||||||||||||||||
| 585 | data row in a given column). | ||||||||||||||||||||||||||||||||||||||||||
| 586 | The separator between the last two columns is re-used if the table has | ||||||||||||||||||||||||||||||||||||||||||
| 587 | more columns than the picture. | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | Similarly, the picture must contain at least two rows and | ||||||||||||||||||||||||||||||||||||||||||
| 590 | the rule between the last two rows is re-used if the actual table has more | ||||||||||||||||||||||||||||||||||||||||||
| 591 | rows than the picture. | ||||||||||||||||||||||||||||||||||||||||||
| 592 | Often pictures have three rows to allow a different separator | ||||||||||||||||||||||||||||||||||||||||||
| 593 | between the title row and the first body row. | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | See "PICTURE SPECIFICATIONS" for examples. | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | =head1 ADDITIONAL PUBLIC METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | =head2 Status Information | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | =item num_body_rows() | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | The number of possibly-multiline I<rows> in the body portion of the table. See B<ROWS> above. | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | =item num_rows() | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | The total number of rows, including the title row. | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | =item rendered_table_height() | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | The number of lines in the entire title including rule lines. | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | =item rendered_title_height() | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | The number of lines in just the title I<row>, including rules before and after | ||||||||||||||||||||||||||||||||||||||||||
| 620 | (unlike B<title_height()> which only counts non-rule lines). | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | =head2 Table Output | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | =item rendered_stringify() | ||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||
| 630 | Returns the entire table as a single string including rule lines. | ||||||||||||||||||||||||||||||||||||||||||
| 631 | This is the same as B<rendered_table()> but returns a string even in | ||||||||||||||||||||||||||||||||||||||||||
| 632 | array context. | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | The object also stringifies to the same result using operator overloading. | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | $string = $tb->rendererd_stringify() | ||||||||||||||||||||||||||||||||||||||||||
| 637 | $string = $tb; # same result | ||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | =item rendered_table() | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | Like C<table()> but includes rule lines. | ||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | $line = $tb->rendered_tables($line_index); # one line | ||||||||||||||||||||||||||||||||||||||||||
| 644 | @lines = $tb->rendered_tables; # all lines | ||||||||||||||||||||||||||||||||||||||||||
| 645 | @lines = $tb->rendered_tables($line_index, $num_tables); | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | Line index 0 is the top rule line (if there is one), | ||||||||||||||||||||||||||||||||||||||||||
| 648 | index 1 is the first "real" title line, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | =item body_rows() | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | =item rendered_body_rows() | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | Returns I<rows>, each of which is a ref to an array containing | ||||||||||||||||||||||||||||||||||||||||||
| 655 | possibly-multiple lines. In scalar context, returns a single array ref | ||||||||||||||||||||||||||||||||||||||||||
| 656 | (valid only for a single row). | ||||||||||||||||||||||||||||||||||||||||||
| 657 | B<rendered_body_rows()> includes a rule line as the last line in each row | ||||||||||||||||||||||||||||||||||||||||||
| 658 | if an interior rule was defined in the I<picture> (it is possible to omit interior rules -- see PICTURE SPECIFICATIONS). | ||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | Row index 0 is the first body row. | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | $lineset = $tb->rendered_body_rows($row_index); # one row | ||||||||||||||||||||||||||||||||||||||||||
| 663 | @linesets = $tb->rendered_body_rows; # all rows | ||||||||||||||||||||||||||||||||||||||||||
| 664 | @linesets = $tb->rendered_body_rows($row_index, $num_rows); | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | =item title_row() | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | =item rendered_title_row() | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | Returns a row representation (i.e. array ref) for the title row. | ||||||||||||||||||||||||||||||||||||||||||
| 671 | This is the same as B<row(0)> or B<rendered_row(0)>. | ||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | =item rendered_title() | ||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | Like C<rendered_table()> but only returns lines from the title row, | ||||||||||||||||||||||||||||||||||||||||||
| 676 | ending with the rule line following the title. | ||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | =item rendered_body() | ||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | Returns lines from the body area of the table, including rule lines | ||||||||||||||||||||||||||||||||||||||||||
| 681 | after each row. Row index 0 is the first line of the first body row. | ||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | =item top_rule() | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | =item mid_rule() | ||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | =item mid_rule($body_row_index) | ||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | =item bot_rule() | ||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | These return the corresponding rendered rule line. | ||||||||||||||||||||||||||||||||||||||||||
| 692 | You normally do not call these yourself because rules are | ||||||||||||||||||||||||||||||||||||||||||
| 693 | automatically included by the "rendered_xxx" methods | ||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | C<mid_rule()> accepts an optional index to retrieve | ||||||||||||||||||||||||||||||||||||||||||
| 696 | other than the first interior rule in the picture. | ||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | =head1 PICTURE SPECIFICATIONS | ||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | Custom separators and rules are specified as a "picture" built from several | ||||||||||||||||||||||||||||||||||||||||||
| 703 | lines. There are four kinds of rules. All are optional: | ||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | =item * Top rule | ||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | =item * Special "mid" rule(s) used only at the indicated position. | ||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | =item * Default "mid" rule, also used between subsequent body rows | ||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | =item * Bottom rule | ||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||
| 717 | Pictures must have at least two rows and columns: | ||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | ┌───┬───┐ /=======\ ⇦ top rule | ||||||||||||||||||||||||||||||||||||||||||
| 720 | │ c │ c │ | c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 721 | ├───┼───┤ |---+---| ⇦ default mid rule | ||||||||||||||||||||||||||||||||||||||||||
| 722 | │ c │ c │ | c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 723 | ╘═══╧═══╛ \=======/ ⇦ bottom rule | ||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | The letter 'B<I<c>>' is a stand-in for real content. Everything | ||||||||||||||||||||||||||||||||||||||||||
| 726 | between 'B<I<c>>'s or at the edge is a separator string. | ||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | With more than two picture rows, special rules are used where indicated | ||||||||||||||||||||||||||||||||||||||||||
| 729 | among the upper rows in the table. | ||||||||||||||||||||||||||||||||||||||||||
| 730 | The last interior rule is the "default" rule, used between further rows | ||||||||||||||||||||||||||||||||||||||||||
| 731 | if there are any. And analogously for columns: | ||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||
| 733 | ⮦ Left-edge separator | ||||||||||||||||||||||||||||||||||||||||||
| 734 | ⏐ ⮦ Special separator | ||||||||||||||||||||||||||||||||||||||||||
| 735 | ⏐ ⏐ ⮦ Default separator | ||||||||||||||||||||||||||||||||||||||||||
| 736 | ↓ ↓ ↓ ⮦ Right-edge separator | ||||||||||||||||||||||||||||||||||||||||||
| 737 | ┌─╥─┬─┐ ┌───╥───┬───┐ ============== ⇦ top rule | ||||||||||||||||||||||||||||||||||||||||||
| 738 | │c║c│c│ │ c ║ c │ c │ | c || c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 739 | ╞═╬═╪═╡ ╞═══╬═══╪═══╡ |===++===+===| ⇦ special rule after title | ||||||||||||||||||||||||||||||||||||||||||
| 740 | │c║c│c│ │ c ║ c │ c │ | c || c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 741 | ┝━╋━┿━┥ ┝━━━╋━━━┿━━━┥ |___||___|___| ⇦ special after 1st body row | ||||||||||||||||||||||||||||||||||||||||||
| 742 | │c║c│c│ │ c ║ c │ c │ | c || c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 743 | ├─╫─┼─┤ ├───╫───┼───┤ |---++---+---| ⇦ default rule | ||||||||||||||||||||||||||||||||||||||||||
| 744 | │c║c│c│ │ c ║ c │ c │ | c || c | c | | ||||||||||||||||||||||||||||||||||||||||||
| 745 | ╘═╩═╧═╛ ╘═══╩═══╧═══╛ ============== ⇦ bottom rule | ||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | In the leftmost example, column separators are single characters | ||||||||||||||||||||||||||||||||||||||||||
| 748 | so there is no padding around content. In the others the separators are | ||||||||||||||||||||||||||||||||||||||||||
| 749 | two or three characters each including spaces for padding, e.g. "|␠", | ||||||||||||||||||||||||||||||||||||||||||
| 750 | "␠|␠" or "␠|". | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | Outer borders can be omitted: | ||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | c║c│c c ║ c │ c c | c | c | ||||||||||||||||||||||||||||||||||||||||||
| 755 | ═╬═╪═ ═══╬═══╪═══ ===+===+=== | ||||||||||||||||||||||||||||||||||||||||||
| 756 | c║c│c c ║ c │ c c | c | c | ||||||||||||||||||||||||||||||||||||||||||
| 757 | ─╫─┼─ ───╫───┼─── ---+---+--- | ||||||||||||||||||||||||||||||||||||||||||
| 758 | c║c│c c ║ c │ c c | c | c | ||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | To get only outer borders, omit the interior rules and use interior | ||||||||||||||||||||||||||||||||||||||||||
| 761 | separators containing only spaces (unless you want cells to touch): | ||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | ┌───┐ ┌─────┐ ======= | ||||||||||||||||||||||||||||||||||||||||||
| 764 | │c c│ │ c c │ | c c | | ||||||||||||||||||||||||||||||||||||||||||
| 765 | │c c│ │ c c │ | c c | | ||||||||||||||||||||||||||||||||||||||||||
| 766 | │c c│ │ c c │ | c c | | ||||||||||||||||||||||||||||||||||||||||||
| 767 | ╘═══╛ ╘═════╛ ======= | ||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | B<RENDERING EXAMPLES> | ||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||
| 771 | If there are more actual rows and/or columns than in the picture, | ||||||||||||||||||||||||||||||||||||||||||
| 772 | the "default" rule and/or column separator is repeated: | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | Picture Rendered Actual Table | ||||||||||||||||||||||||||||||||||||||||||
| 775 | ┌─╥─┬─┐ ┌──────╥─────┬──────────┬────────────┐ ⇦ top rule | ||||||||||||||||||||||||||||||||||||||||||
| 776 | │c║c│c│ │ NAME ║ AC │ NUMBER │ Pet's Name │ | ||||||||||||||||||||||||||||||||||||||||||
| 777 | ╞═╬═╪═╡ ╞══════╬═════╪══════════╪════════════╡ ⇦ special rule | ||||||||||||||||||||||||||||||||||||||||||
| 778 | │c║c│c│ │ Sam ║ 800 │ 555-1212 │ Cutesy │ | ||||||||||||||||||||||||||||||||||||||||||
| 779 | ├─╫─┼─┤ ├──────╫─────┼──────────┼────────────┤ ⇦ default rule | ||||||||||||||||||||||||||||||||||||||||||
| 780 | │c║c│c│ │ Mary ║ 880 │ 123-4567 │ Killer │ | ||||||||||||||||||||||||||||||||||||||||||
| 781 | ╘═╩═╧═╛ ├──────╫─────┼──────────┼────────────┤ ⇦ default rule | ||||||||||||||||||||||||||||||||||||||||||
| 782 | │ Don ║ 880 │ 123-4567 │ Tweetie │ | ||||||||||||||||||||||||||||||||||||||||||
| 783 | ├──────╫─────┼──────────┼────────────┤ ⇦ default rule | ||||||||||||||||||||||||||||||||||||||||||
| 784 | │ Mico ║ 880 │ 123-4567 │ Tabby │ | ||||||||||||||||||||||||||||||||||||||||||
| 785 | ╘══════╩═════╧══════════╧════════════╛ ⇦ bottom rule | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | The edge separators are always used, as are the top & bottom rules (if defined), | ||||||||||||||||||||||||||||||||||||||||||
| 788 | even if there are fewer rows or columns than in the picture: | ||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | ┌───┰───┬───┐ ┌───────┐ ⇦ top rule | ||||||||||||||||||||||||||||||||||||||||||
| 791 | │ c ║ c │ c │ │Meaning│ | ||||||||||||||||||||||||||||||||||||||||||
| 792 | ┝━━━╋━━━┿━━━┥ │of life│ | ||||||||||||||||||||||||||||||||||||||||||
| 793 | │ c ║ c │ c │ ┝━━━━━━━┥ ⇦ special after-title rule | ||||||||||||||||||||||||||||||||||||||||||
| 794 | ├───╫───┼───┤ │ 42 │ | ||||||||||||||||||||||||||||||||||||||||||
| 795 | │ c ║ c │ c │ ╘═══════╛ ⇦ bottom rule | ||||||||||||||||||||||||||||||||||||||||||
| 796 | ╘═══╩═══╧═══╛ | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | If there is a title row but no body rows, | ||||||||||||||||||||||||||||||||||||||||||
| 799 | only the top and bottom rules are used: | ||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | ┌──────╥─────┬────────────┐ ⇦ top rule | ||||||||||||||||||||||||||||||||||||||||||
| 802 | │ NAME ║ AC │ NUMBER │ | ||||||||||||||||||||||||||||||||||||||||||
| 803 | ╘══════╩═════╧════════════╛ ⇦ bottom rule | ||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | If there are no titles or data, nothing is rendered | ||||||||||||||||||||||||||||||||||||||||||
| 806 | e.g. the object stringifies to "". | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | =head1 PAGER EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | Please see L<Text::Table::Boxed::Pager> for an example of using B<rows> to view a table on a terminal, | ||||||||||||||||||||||||||||||||||||||||||
| 811 | keeping multi-line rows together when possible. | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | =head1 ACKNOWLEDGMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | This module was inspired the example code in the Text::Table | ||||||||||||||||||||||||||||||||||||||||||
| 816 | documentation by Anno Siegel and/or Shlomi Fish, and | ||||||||||||||||||||||||||||||||||||||||||
| 817 | a post at | ||||||||||||||||||||||||||||||||||||||||||
| 818 | L<https://stackoverflow.com/questions/30762521/how-can-i-print-a-table-with-multi-line-strings-using-the-texttable-module> | ||||||||||||||||||||||||||||||||||||||||||
| 819 | by stackoverflow user "ThisSuitIsBlackNot". | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | Text::Table::Boxed is new in 2024 and actively maintained. | ||||||||||||||||||||||||||||||||||||||||||
| 824 | Please report issues! | ||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | L<https://github.com/jimav/Text-Table-Boxed/issues> | ||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | Jim Avera (jim.avera at gmail) | ||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||
| 832 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | CC0 or Public Domain. | ||||||||||||||||||||||||||||||||||||||||||
| 835 | However your application is likely subject to the more restrictive licenses | ||||||||||||||||||||||||||||||||||||||||||
| 836 | of Text::Table and other modules. | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | =for Pod::Coverage add new rendered_rows rows | ||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | =for Pod::Coverage btw btwN oops | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 843 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||