| 1 | package Term::Table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | our $VERSION = '0.016'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Term::Table::Cell(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Term::Table::Util qw/term_size uni_length USE_GCS/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use List::Util qw/max sum/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Carp qw/croak carp/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Term::Table::HashBase qw/rows _columns collapse max_width mark_tail sanitize show_header auto_columns no_collapse header allow_overflow pad/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | sub BORDER_SIZE() { 4 } # '| ' and ' |' borders | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | sub DIV_SIZE() { 3 } # ' | ' column delimiter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | sub CELL_PAD_SIZE() { 2 } # space on either side of the | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 16 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=16 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | croak "You cannot have a table with no rows" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 16 | ▶ | unless $self->{+ROWS} && @{$self->{+ROWS}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"rows"} and @{$self->{"rows"};}
MC/DC0%0/2
$self->{"rows"} and @{$self->{"rows"};}
$self->{"rows"}
@{$self->{"rows"};}
Truth table33%1/3
A and B
A= $self->{"rows"}B= @{$self->{"rows"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 16 | ▶ | $self->{+MAX_WIDTH} ||= term_size(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"max_width"} ||= term_size()
MC/DC0%0/2
$self->{"max_width"} ||= term_size()
$self->{"max_width"}
term_size()
Truth table66%2/3
A ||= B
A= $self->{"max_width"}B= term_size()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 16 | ▶ | $self->{+NO_COLLAPSE} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"no_collapse"} ||= {}
MC/DC100%1/1
$self->{"no_collapse"} ||= {}
$self->{"no_collapse"}
Truth table100%2/2
A
A= $self->{"no_collapse"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | ▶ | if (ref($self->{+NO_COLLAPSE}) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | $self->{+NO_COLLAPSE} = {map { ($_ => 1) } @{$self->{+NO_COLLAPSE}}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 16 | ▶ | if ($self->{+NO_COLLAPSE} && $self->{+HEADER}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"no_collapse"} and $self->{"header"}
MC/DC50%1/2
$self->{"no_collapse"} and $self->{"header"}
$self->{"no_collapse"}
$self->{"header"}
Truth table66%2/3
A and B
A= $self->{"no_collapse"}B= $self->{"header"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 12 | my $header = $self->{+HEADER}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | ▶ | for(my $idx = 0; $idx < @$header; $idx++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 45 | ▶ | $self->{+NO_COLLAPSE}->{$idx} ||= $self->{+NO_COLLAPSE}->{$header->[$idx]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"no_collapse"}{$idx} ||= $self->{"no_collapse"}{$header->[$idx]}
MC/DC50%1/2
$self->{"no_collapse"}{$idx} ||= $self->{"no_collapse"}{$header->[$idx]}
$self->{"no_collapse"}{$idx}
$self->{"no_collapse"}{$header->[$idx]}
Truth table66%2/3
A ||= B
A= $self->{"no_collapse"}{$idx}B= $self->{"no_collapse"}{$header->[$idx]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 16 | ▶ | $self->{+PAD} = 4 unless defined $self->{+PAD}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 16 | ▶ | $self->{+COLLAPSE} = 1 unless defined $self->{+COLLAPSE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | ▶ | $self->{+SANITIZE} = 1 unless defined $self->{+SANITIZE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | ▶ | $self->{+MARK_TAIL} = 1 unless defined $self->{+MARK_TAIL}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 16 | ▶ | if($self->{+HEADER}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 12 | ▶ | $self->{+SHOW_HEADER} = 1 unless defined $self->{+SHOW_HEADER}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | $self->{+HEADER} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | $self->{+AUTO_COLUMNS} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | $self->{+SHOW_HEADER} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sub columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 17 | ▶ | $self->regen_columns unless $self->{+_COLUMNS}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 15 | return $self->{+_COLUMNS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | sub regen_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 16 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
regen_columns: called CC=29 SCAR=34.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 16 | ▶ | my $has_header = $self->{+SHOW_HEADER} && @{$self->{+HEADER}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{'show_header'} && @{$self->{'header'};}
MC/DC50%1/2
$self->{'show_header'} && @{$self->{'header'};}
$self->{'show_header'}
@{$self->{'header'};}
Truth table66%2/3
A && B
A= $self->{'show_header'}B= @{$self->{'header'};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 16 | ▶ | my %new_col = (width => 0, count => $has_header ? -1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 16 | my $cols = [map { {%new_col} } @{$self->{+HEADER}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 16 | my @rows = @{$self->{+ROWS}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 16 | ▶ | for my $row ($has_header ? ($self->{+HEADER}, @rows) : (@rows)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 38 | for my $ci (0 .. max(@$cols - 1, @$row - 1)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 137 | ▶ | $cols->[$ci] ||= {%new_col} if $self->{+AUTO_COLUMNS}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$cols->[$ci] ||= {%new_col}
MC/DC100%1/1
$cols->[$ci] ||= {%new_col}
$cols->[$ci]
Truth table100%2/2
A
A= $cols->[$ci]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 137 | ▶ | my $c = $cols->[$ci] or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 137 | ▶ | $c->{idx} ||= $ci; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$c->{"idx"} ||= $ci
MC/DC100%2/2
$c->{"idx"} ||= $ci
$c->{"idx"}
$ci
Truth table100%3/3
A ||= B
A= $c->{"idx"}B= $ci
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 137 | ▶ | $c->{rows} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$c->{"rows"} ||= []
MC/DC100%1/1
$c->{"rows"} ||= []
$c->{"rows"}
Truth table100%2/2
A
A= $c->{"rows"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 137 | my $r = $row->[$ci]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 137 | ▶ | $r = Term::Table::Cell->new(value => $r) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
builtin::blessed($r) and $r->isa("Term::Table::Cell") || $r->isa("Term::Table::CellStack") || $r->isa("Term::Table::Spacer")
$r->isa("Term::Table::Cell") or $r->isa("Term::Table::CellStack") or $r->isa("Term::Table::Spacer")
$r->isa("Term::Table::Cell") or $r->isa("Term::Table::CellStack")
MC/DC0%0/4
builtin::blessed($r) and $r->isa("Term::Table::Cell") || $r->isa("Term::Table::CellStack") || $r->isa("Term::Table::Spacer")
builtin::blessed($r)
$r->isa("Term::Table::Cell")
$r->isa("Term::Table::CellStack")
$r->isa("Term::Table::Spacer")
Truth table20%1/5
A and B or C or D
A= builtin::blessed($r)B= $r->isa("Term::Table::Cell")C= $r->isa("Term::Table::CellStack")D= $r->isa("Term::Table::Spacer")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | unless blessed($r) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | && ($r->isa('Term::Table::Cell') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | || $r->isa('Term::Table::CellStack') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | || $r->isa('Term::Table::Spacer')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 137 | ▶ | $r->sanitize if $self->{+SANITIZE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 137 | ▶ | $r->mark_tail if $self->{+MARK_TAIL}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 137 | my $rs = $r->width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 137 | ▶ | $c->{width} = $rs if $rs > $c->{width}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 137 | ▶ | $c->{count}++ if $rs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 137 | push @{$c->{rows}} => $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # Remove any empty columns we can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 45 | ▶ | @$cols = grep {$_->{count} > 0 || $self->{+NO_COLLAPSE}->{$_->{idx}}} @$cols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 16 | ▶ | if $self->{+COLLAPSE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 16 | my $current = sum(map {$_->{width}} @$cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 16 | my $border = sum(BORDER_SIZE, $self->{+PAD}, DIV_SIZE * (@$cols - 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 16 | my $total = $current + $border; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 16 | ▶ | if ($total > $self->{+MAX_WIDTH}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 7 | my $fair = ($self->{+MAX_WIDTH} - $border) / @$cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 7 | ▶ | if ($fair < 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | ▶ | return $self->{+_COLUMNS} = $cols if $self->{+ALLOW_OVERFLOW}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | croak "Table is too large ($total including $self->{+PAD} padding) to fit into max-width ($self->{+MAX_WIDTH})"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | my $under = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | my @fix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | for my $c (@$cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | ▶ | if ($c->{width} > $fair) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 13 | push @fix => $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $under += $c->{width}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Recalculate fairness | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | $fair = int(($self->{+MAX_WIDTH} - $border - $under) / @fix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | ▶ | if ($fair < 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | return $self->{+_COLUMNS} = $cols if $self->{+ALLOW_OVERFLOW}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | croak "Table is too large ($total including $self->{+PAD} padding) to fit into max-width ($self->{+MAX_WIDTH})"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Adjust over-long columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | $_->{width} = $fair for @fix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 13 | $self->{+_COLUMNS} = $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | sub render { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=31 SCAR=35.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 17 | my $cols = $self->columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 15 | for my $col (@$cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 49 | for my $cell (@{$col->{rows}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 132 | $cell->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 15 | my $width = sum(BORDER_SIZE, $self->{+PAD}, DIV_SIZE * @$cols, map { $_->{width} } @$cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | #<<< NO-TIDY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 15 | my $border = '+' . join('+', map { '-' x ($_->{width} + CELL_PAD_SIZE) } @$cols) . '+'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 15 | my $template = '|' . join('|', map { my $w = $_->{width} + CELL_PAD_SIZE; '%s' } @$cols) . '|'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 15 | my $spacer = '|' . join('|', map { ' ' x ($_->{width} + CELL_PAD_SIZE) } @$cols) . '|'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | #>>> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 15 | my @out = ($border); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 15 | my ($row, $split, $found) = (0, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 15 | while(1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 149 | my @row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 149 | my $is_spacer = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 149 | for my $col (@$cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 536 | my $r = $col->{rows}->[$row]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 536 | ▶ | unless($r) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 49 | push @row => ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 49 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 487 | my ($v, $vw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 487 | ▶ | if ($r->isa('Term::Table::Cell')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 449 | my $lw = $r->border_left_width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 449 | my $rw = $r->border_right_width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 449 | $vw = $col->{width} - $lw - $rw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 449 | $v = $r->break->next($vw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | elsif ($r->isa('Term::Table::CellStack')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 38 | ($v, $vw) = $r->break->next($col->{width}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | elsif ($r->isa('Term::Table::Spacer')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $is_spacer = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 487 | ▶ | if ($is_spacer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | elsif (defined $v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 249 | $found++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 249 | ▶ | my $bcolor = $r->border_color || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->border_color || ''
MC/DC0%0/1
$r->border_color || ''
$r->border_color
Truth table50%1/2
A
A= $r->border_color
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 249 | ▶ | my $vcolor = $r->value_color || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->value_color || ''
MC/DC0%0/1
$r->value_color || ''
$r->value_color
Truth table50%1/2
A
A= $r->value_color
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 249 | ▶ | my $reset = $r->reset_color || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->reset_color || ''
MC/DC0%0/1
$r->reset_color || ''
$r->reset_color
Truth table50%1/2
A
A= $r->reset_color
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 249 | ▶ | if (my $need = $vw - uni_length($v)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $v .= ' ' x $need; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 249 | my $rt = "${reset}${bcolor}\%s${reset} ${vcolor}\%s${reset} ${bcolor}\%s${reset}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 249 | ▶ | push @row => sprintf($rt, $r->border_left || '', $v, $r->border_right || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$r->border_left || ''
$r->border_right || ''
MC/DC100%1/1
$r->border_left || ''
$r->border_left
MC/DC100%1/1
$r->border_right || ''
$r->border_right
Truth table100%2/2
A
A= $r->border_left
Truth table100%2/2
A
A= $r->border_right
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 238 | push @row => ' ' x ($col->{width} + 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 149 | ▶ | if (!grep {$_ && m/\S/} @row) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 53 | ▶ | last unless $found || $is_spacer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$found or $is_spacer
MC/DC50%1/2
$found or $is_spacer
$found
$is_spacer
Truth table66%2/3
A or B
A= $foundB= $is_spacer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 38 | ▶ | push @out => $border if $row == 0 && $self->{+SHOW_HEADER} && @{$self->{+HEADER}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$row == 0 and $self->{"show_header"} and @{$self->{"header"};}
$row == 0 and $self->{"show_header"}
MC/DC66%2/3
$row == 0 and $self->{"show_header"} and @{$self->{"header"};}
$row == 0
$self->{"show_header"}
@{$self->{"header"};}
Truth table75%3/4
A and B and C
A= $row == 0B= $self->{"show_header"}C= @{$self->{"header"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 38 | ▶ | push @out => $spacer if $split > 1 || $is_spacer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$split > 1 or $is_spacer
MC/DC50%1/2
$split > 1 or $is_spacer
$split > 1
$is_spacer
Truth table66%2/3
A or B
A= $split > 1B= $is_spacer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 38 | $row++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 38 | $split = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 38 | $found = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 38 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 96 | ▶ | if ($split == 1 && @out > 1 && $out[-2] ne $border && $out[-2] ne $spacer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$split == 1 and @out > 1 and $out[-2] ne $border and $out[-2] ne $spacer
$split == 1 and @out > 1 and $out[-2] ne $border
$split == 1 and @out > 1
MC/DC0%0/4
$split == 1 and @out > 1 and $out[-2] ne $border and $out[-2] ne $spacer
$split == 1
@out > 1
$out[-2] ne $border
$out[-2] ne $spacer
Truth table60%3/5
A and B and C and D
A= $split == 1B= @out > 1C= $out[-2] ne $borderD= $out[-2] ne $spacer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $last = pop @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | push @out => ($spacer, $last); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 96 | push @out => sprintf($template, @row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 96 | $split++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 15 | ▶ | pop @out while @out && $out[-1] eq $spacer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@out and $out[-1] eq $spacer
MC/DC50%1/2
@out and $out[-1] eq $spacer
@out
$out[-1] eq $spacer
Truth table66%2/3
A and B
A= @outB= $out[-1] eq $spacer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 15 | unless (USE_GCS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | for my $row (@out) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | next unless $row =~ m/[^\x00-\x7F]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | unshift @out => "Unicode::GCString is not installed, table may not display all unicode characters properly"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 15 | return (@out, $border); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | sub display { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my ($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my @parts = map "$_\n", $self->render; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | print $fh @parts if $fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | print @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||