blib/lib/Text/Table/ASV.pm

filter: Statementstmt 10.3% 3 / 29 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 50.0% 1 / 2 totaltotal 7.4% 4 / 54 CC 10 SCAR 36.0
CC
10
Cov
7%
table
56.0
max
20.0
_encode
2.0
CRAP 36.6
↑ Summary
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
BranchTrueFalseTotal
my $rows = $params{"rows"} or die "Must provide rows!" 0 0 0
21  
22 0 ▶ my $header_row = defined $params{header_row} ? $params{header_row} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'header_row'} ? : 0 0 0
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
BranchTrueFalseTotal
if $i == 1 and not $header_row 0 0 0
Condition0%0/3
$i == 1 and not $header_row
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
33 push @table, join(
34 "\x1f",
35 0 ▶ map { _encode(defined($row->[$_]) ? $row->[$_] : '') } (0..$max_index)
Branch: 1 branch
BranchTrueFalseTotal
defined $row->[$_] ? : 0 0 0
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
BranchTrueFalseTotal
unless @_ 0 0 0
46 0 my $res = $_[0];
47 0 my $i = 0;
48 0 ▶ while (++$i < @_) { $res = $_[$i] if $_[$i] > $res }
Branch: 2 branches
BranchTrueFalseTotal
if (++$i < @_) 0 0 0
if $_[$i] > $res 0 0 0
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__
↑ Summary