| 1 | package Silki::Formatter::HTMLToWiki::Table; | ||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||
| 3 | 1 | $Silki::Formatter::HTMLToWiki::Table::VERSION = '0.29'; | |||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use List::AllUtils qw( all max sum ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Silki::Formatter::HTMLToWiki::Table::Cell; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Silki::Types qw( Str ArrayRef Int Bool Maybe ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 1 | my $row = subtype as ArrayRef ['Silki::Formatter::HTMLToWiki::Table::Cell']; | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | has _thead_rows => ( | ||||||||||||||||||||||||||||||
| 22 | traits => ['Array'], | ||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||
| 24 | isa => ArrayRef [$row], | ||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 26 | 1 | handles => { | |||||||||||||||||||||||||||||
| 27 | _add_thead_row => 'push', | ||||||||||||||||||||||||||||||
| 28 | _has_thead => 'count', | ||||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||||
| 30 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | 1 | has _in_thead => ( | |||||||||||||||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||||||||||||||
| 35 | isa => Bool, | ||||||||||||||||||||||||||||||
| 36 | default => 0, | ||||||||||||||||||||||||||||||
| 37 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | has _tbodies => ( | ||||||||||||||||||||||||||||||
| 41 | traits => ['Array'], | ||||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||||
| 43 | isa => ArrayRef [ ArrayRef [$row] ], | ||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 45 | 1 | handles => { | |||||||||||||||||||||||||||||
| 46 | _add_tbody => 'push', | ||||||||||||||||||||||||||||||
| 47 | _has_tbodies => 'count', | ||||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||||
| 49 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | has _current_tbody => ( | ||||||||||||||||||||||||||||||
| 53 | traits => ['Array'], | ||||||||||||||||||||||||||||||
| 54 | is => 'ro', | ||||||||||||||||||||||||||||||
| 55 | isa => ArrayRef [$row], | ||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 57 | 1 | handles => { | |||||||||||||||||||||||||||||
| 58 | _add_tbody_row => 'push', | ||||||||||||||||||||||||||||||
| 59 | _reset_current_tbody => 'clear', | ||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||
| 61 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | has _current_row => ( | ||||||||||||||||||||||||||||||
| 65 | traits => ['Array'], | ||||||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||||
| 67 | isa => $row, | ||||||||||||||||||||||||||||||
| 68 | 6 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 69 | 1 | handles => { | |||||||||||||||||||||||||||||
| 70 | _add_cell => 'push', | ||||||||||||||||||||||||||||||
| 71 | _reset_row => 'clear', | ||||||||||||||||||||||||||||||
| 72 | _row_has_cells => 'count', | ||||||||||||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||||||||||||
| 74 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | 1 | has _current_cell => ( | |||||||||||||||||||||||||||||
| 78 | is => 'rw', | ||||||||||||||||||||||||||||||
| 79 | isa => 'Silki::Formatter::HTMLToWiki::Table::Cell', | ||||||||||||||||||||||||||||||
| 80 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 1 | has _max_cell_widths => ( | |||||||||||||||||||||||||||||
| 84 | is => 'ro', | ||||||||||||||||||||||||||||||
| 85 | isa => ArrayRef [Int], | ||||||||||||||||||||||||||||||
| 86 | lazy => 1, | ||||||||||||||||||||||||||||||
| 87 | builder => '_build_max_cell_widths', | ||||||||||||||||||||||||||||||
| 88 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 5 | ▶ | sub _start_thead { | ||||||||||||||||||||||||||||
|
Subroutine
_start_thead: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 92 | 5 | my $self = shift; | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | 5 | $self->_set_in_thead(1); | |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | sub _end_thead { | ||||||||||||||||||||||||||||
|
Subroutine
_end_thead: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 98 | 5 | my $self = shift; | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | 5 | $self->_set_in_thead(0); | |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | 7 | ▶ | sub _start_tbody { | ||||||||||||||||||||||||||||
|
Subroutine
_start_tbody: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 104 | 7 | my $self = shift; | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | 7 | $self->_reset_current_tbody(); | |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||
| 109 | 7 | ▶ | sub _end_tbody { | ||||||||||||||||||||||||||||
|
Subroutine
_end_tbody: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 110 | 7 | my $self = shift; | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||
| 112 | 7 | $self->_add_tbody( [ @{ $self->_current_tbody() } ] ); | |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | 20 | ▶ | sub _start_tr { | ||||||||||||||||||||||||||||
|
Subroutine
_start_tr: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 116 | 20 | my $self = shift; | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | 20 | $self->_reset_row(); | |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | 20 | ▶ | sub _end_tr { | ||||||||||||||||||||||||||||
|
Subroutine
_end_tr: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 122 | 20 | my $self = shift; | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | 20 | ▶ | if ( $self->_in_thead() ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 125 | 6 | $self->_add_thead_row( [ @{ $self->_current_row() } ] ); | |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||||
| 128 | 14 | $self->_add_tbody_row( [ @{ $self->_current_row() } ] ); | |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | 12 | ▶ | sub _start_th { | ||||||||||||||||||||||||||||
|
Subroutine
_start_th: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 134 | 12 | my $self = shift; | |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||
| 136 | 12 | $self->_start_cell(@_); | |||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | 12 | ▶ | sub _end_th { | ||||||||||||||||||||||||||||
|
Subroutine
_end_th: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 140 | 12 | my $self = shift; | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | 12 | $self->_end_cell(@_); | |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | 26 | ▶ | sub _start_td { | ||||||||||||||||||||||||||||
|
Subroutine
_start_td: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 146 | 26 | my $self = shift; | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | 26 | $self->_start_cell(@_); | |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | 26 | ▶ | sub _end_td { | ||||||||||||||||||||||||||||
|
Subroutine
_end_td: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 152 | 26 | my $self = shift; | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||
| 154 | 26 | $self->_end_cell(@_); | |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||
| 157 | 38 | ▶ | sub _start_cell { | ||||||||||||||||||||||||||||
|
Subroutine
_start_cell: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||
| 158 | 38 | my $self = shift; | |||||||||||||||||||||||||||||
| 159 | 38 | my $node = shift; | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | 38 | ▶ | $self->_set_current_cell( | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%4/4
$node->attr('colspan') || 1
$node->attr('align') || 'left'
MC/DC100%1/1
$node->attr('colspan') || 1
$node->attr('colspan')
MC/DC100%1/1
$node->attr('align') || 'left'
$node->attr('align')
Truth table100%2/2
A
A= $node->attr('colspan')
Truth table100%2/2
A
A= $node->attr('align')
| |||||||||||||||||||||||||||||||
| 162 | Silki::Formatter::HTMLToWiki::Table::Cell->new( | ||||||||||||||||||||||||||||||
| 163 | colspan => $node->attr('colspan') || 1, | ||||||||||||||||||||||||||||||
| 164 | alignment => $node->attr('align') || 'left', | ||||||||||||||||||||||||||||||
| 165 | is_header_cell => $node->tag() eq 'th' ? 1 : 0, | ||||||||||||||||||||||||||||||
| 166 | ) | ||||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||
| 170 | 38 | ▶ | sub _end_cell { | ||||||||||||||||||||||||||||
|
Subroutine
_end_cell: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 171 | 38 | my $self = shift; | |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||
| 173 | 38 | $self->_add_cell( $self->_current_cell() ); | |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||
| 176 | 6 | ▶ | sub finalize { | ||||||||||||||||||||||||||||
|
Subroutine
finalize: called CC=7 SCAR=22.6
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 177 | 6 | my $self = shift; | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||
| 179 | 6 | ▶ | unless ( $self->_has_tbodies() ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 180 | 0 | $self->_end_tbody(); | |||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||
| 183 | 6 | ▶ | unless ( $self->_has_thead() ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 184 | 1 | my $tbody = $self->_tbodies()->[0]; | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | while ( my $row = shift @{$tbody} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | # If all the cells in a row are <th> cells, _or_ all the content | ||||||||||||||||||||||||||||||
| 189 | # in each cell is bold, it's a header row. | ||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | if ( ( all { $_->is_header_cell() } @{$row} ) | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.5
Branch: 1 branch
Condition33%1/3
&all(sub {
$_->is_header_cell;
}
, @{$row;}) or &all(sub {
$_->content =~ /^\s*\*\*.+\*\*\s*$/;
}
, @{$row;})
MC/DC0%0/2
&all(sub {
$_->is_header_cell;
}
, @{$row;}) or &all(sub {
$_->content =~ /^\s*\*\*.+\*\*\s*$/;
}
, @{$row;})
&all(sub {
$_->is_header_cell;
}
, @{$row;})
&all(sub {
$_->content =~ /^\s*\*\*.+\*\*\s*$/;
}
, @{$row;})
Truth table33%1/3
A or B
A= &all(sub {
$_->is_header_cell;
}
, @{$row;})B= &all(sub {
$_->content =~ /^\s*\*\*.+\*\*\s*$/;
}
, @{$row;})
| |||||||||||||||||||||||||||||||
| 191 | 1 | ▶ | || ( all { $_->content() =~ /^\s*\*\*.+\*\*\s*$/ } @{$row} ) ) | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 192 | { | ||||||||||||||||||||||||||||||
| 193 | 0 | for my $cell ( @{$row} ) { | |||||||||||||||||||||||||||||
| 194 | 0 | my $content = $cell->content(); | |||||||||||||||||||||||||||||
| 195 | 0 | $content =~ s/^(\s*)\*\*(.+)\*\*(\s*)$/$1$2$3/; | |||||||||||||||||||||||||||||
| 196 | 0 | $cell->set_content($content); | |||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||
| 199 | 0 | $self->_add_thead_row($row); | |||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||
| 201 | else { | ||||||||||||||||||||||||||||||
| 202 | 1 | unshift @{$tbody}, $row; | |||||||||||||||||||||||||||||
| 203 | 1 | last; | |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||
| 209 | 6 | ▶ | sub as_markdown { | ||||||||||||||||||||||||||||
|
Subroutine
as_markdown: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 210 | 6 | my $self = shift; | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||
| 212 | 6 | my @dashes; | |||||||||||||||||||||||||||||
| 213 | 6 | for my $width ( @{ $self->_max_cell_widths() } ) { | |||||||||||||||||||||||||||||
| 214 | 13 | push @dashes, $width + 4; | |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||
| 217 | 6 | my @rows; | |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||
| 219 | 6 | my $divider = q{+}; | |||||||||||||||||||||||||||||
| 220 | 6 | $divider .= join q{+}, map { q{-} x $_ } @dashes; | |||||||||||||||||||||||||||||
| 221 | 6 | $divider .= q{+}; | |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||
| 223 | 6 | ▶ | if ( $self->_has_thead() ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 224 | 5 | push @rows, $divider; | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||
| 226 | push @rows, | ||||||||||||||||||||||||||||||
| 227 | 5 | map { $self->_markdown_for_row($_) } @{ $self->_thead_rows() }; | |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | 5 | push @rows, $divider; | |||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||
| 232 | 6 | my @tbodies = @{ $self->_tbodies() }; | |||||||||||||||||||||||||||||
| 233 | 6 | for my $tbody (@tbodies) { | |||||||||||||||||||||||||||||
| 234 | 7 | push @rows, map { $self->_markdown_for_row($_) } @{$tbody}; | |||||||||||||||||||||||||||||
| 235 | 7 | ▶ | push @rows, q{} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 236 | if $tbody ne $tbodies[-1]; | ||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||
| 239 | 6 | ▶ | push @rows, $divider | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 240 | if $self->_has_thead(); | ||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||
| 242 | 6 | return join q{}, map { $_ . "\n" } @rows; | |||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||
| 245 | 20 | ▶ | sub _markdown_for_row { | ||||||||||||||||||||||||||||
|
Subroutine
_markdown_for_row: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 246 | 20 | my $self = shift; | |||||||||||||||||||||||||||||
| 247 | 20 | my $row = shift; | |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||
| 249 | 20 | my @widths = @{ $self->_max_cell_widths() }; | |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||
| 251 | 20 | my $md = q{|}; | |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||
| 253 | 20 | my @cells; | |||||||||||||||||||||||||||||
| 254 | 20 | for my $cell ( @{$row} ) { | |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||
| 256 | # A multi-column cell needs to be as wide as all the columns it spans | ||||||||||||||||||||||||||||||
| 257 | 38 | my $width = sum( splice @widths, 0, $cell->colspan() ); | |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||
| 259 | 38 | $md .= $cell->formatted_content($width); | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | 38 | $md .= q{|} x $cell->colspan(); | |||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||
| 264 | 20 | return $md; | |||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||
| 267 | 6 | ▶ | sub _build_max_cell_widths { | ||||||||||||||||||||||||||||
|
Subroutine
_build_max_cell_widths: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||
| 268 | 6 | my $self = shift; | |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||
| 270 | 6 | my @widths; | |||||||||||||||||||||||||||||
| 271 | 6 | for my $row ( $self->_all_rows() ) { | |||||||||||||||||||||||||||||
| 272 | 20 | for my $x ( 0 .. $#{$row} ) { | |||||||||||||||||||||||||||||
| 273 | 38 | ▶ | $widths[$x] ||= 0; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$widths[$x] ||= 0
MC/DC100%1/1
$widths[$x] ||= 0
$widths[$x]
Truth table100%2/2
A
A= $widths[$x]
| |||||||||||||||||||||||||||||||
| 274 | 38 | $widths[$x] = max( $widths[$x], length $row->[$x]->content() ); | |||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||
| 278 | 6 | return \@widths; | |||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||
| 281 | 6 | ▶ | sub _all_rows { | ||||||||||||||||||||||||||||
|
Subroutine
_all_rows: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 282 | 6 | my $self = shift; | |||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||
| 284 | 6 | return @{ $self->_thead_rows() }, map { @{$_} } @{ $self->_tbodies() }; | |||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||
| 287 | 38 | ▶ | sub print { | ||||||||||||||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 288 | 38 | my $self = shift; | |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||
| 290 | 38 | $self->_current_cell()->append_content( $_[0] ); | |||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||
| 293 | 1 | __PACKAGE__->meta()->make_immutable(); | |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||
| 295 | 1 | 1; | |||||||||||||||||||||||||||||