| 1 | package Text::Table::ASV; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $DATE = '2021-02-20'; # DATE | |||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.002'; # VERSION | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | #IFUNBUILT | ||||||||||||||||||||||||||||
| 7 | # # use 5.010001; | ||||||||||||||||||||||||||||
| 8 | # # use strict; | ||||||||||||||||||||||||||||
| 9 | # # use warnings; | ||||||||||||||||||||||||||||
| 10 | #END IFUNBUILT | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub _encode { | ||||||||||||||||||||||||||
|
Subroutine
_encode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 13 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 14 | 0 | $val =~ s/[\x1c\x1d\x1e\x1f]/ /g; | |||||||||||||||||||||||||||
| 15 | 0 | $val; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub table { | ||||||||||||||||||||||||||
|
Subroutine
table: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 20 | 0 | ▶ | my $rows = $params{rows} or die "Must provide rows!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $header_row = defined $params{header_row} ? $params{header_row} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | my $max_index = _max_array_index($rows); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # here we go... | ||||||||||||||||||||||||||||
| 26 | 0 | my @table; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # then the data | ||||||||||||||||||||||||||||
| 29 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 30 | 0 | foreach my $row ( @{ $rows }[0..$#$rows] ) { | |||||||||||||||||||||||||||
| 31 | 0 | $i++; | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | next if $i==1 && !$header_row; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i == 1 and not $header_row
MC/DC0%0/2
$i == 1 and not $header_row
$i == 1
not $header_row
Truth table0%0/3
A and not(B)
A= $i == 1B= not $header_row
| |||||||||||||||||||||||||||||
| 33 | push @table, join( | ||||||||||||||||||||||||||||
| 34 | "\x1f", | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | map { _encode(defined($row->[$_]) ? $row->[$_] : '') } (0..$max_index) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | return join("\x1e", grep {$_} @table); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # FROM_MODULE: PERLANCAR::List::Util::PP | ||||||||||||||||||||||||||||
| 43 | # BEGIN_BLOCK: max | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub max { | ||||||||||||||||||||||||||
|
Subroutine
max: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return undef unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | my $res = $_[0]; | |||||||||||||||||||||||||||
| 47 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | while (++$i < @_) { $res = $_[$i] if $_[$i] > $res } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 49 | 0 | $res; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | # END_BLOCK: max | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # return highest top-index from all rows in case they're different lengths | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub _max_array_index { | ||||||||||||||||||||||||||
|
Subroutine
_max_array_index: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 55 | 0 | my $rows = shift; | |||||||||||||||||||||||||||
| 56 | 0 | return max( map { $#$_ } @$rows ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||
| 60 | # ABSTRACT: Generate ASV (ASCII separated value a.k.a. DEL a.ka. delimited ASCII) | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||