blib/lib/Text/Table/TSV.pm

filter: Statementstmt 11.1% 3 / 27 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 50.0% 1 / 2 totaltotal 9.3% 4 / 43 CC 7 SCAR 28.0
CC
7
Cov
8%
table
20.0
max
20.0
_encode
2.0
CRAP 16.4
↑ Summary
1 package Text::Table::TSV;
2  
3 1 our $DATE = '2019-01-17'; # 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/\t/ /g;
15 0 $val;
16 }
17  
18 0 ▶sub table {
Subroutine table: not called CC=4 SCAR=30.0
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 $max_index = _max_array_index($rows);
23  
24 # here we go...
25 0 my @table;
26  
27 # then the data
28 0 my $i = 0;
29 0 foreach my $row ( @{ $rows }[0..$#$rows] ) {
30 0 $i++;
31 push @table, join(
32 "\t",
33 0 ▶ map { _encode(defined($row->[$_]) ? $row->[$_] : '') } (0..$max_index)
Branch: 1 branch
BranchTrueFalseTotal
defined $row->[$_] ? : 0 0 0
34 ), "\n";
35 }
36  
37 0 return join("", grep {$_} @table);
38 }
39  
40 # FROM_MODULE: PERLANCAR::List::Util::PP
41 # BEGIN_BLOCK: max
42 0 ▶sub max {
Subroutine max: not called CC=4 SCAR=30.0
Pod undocumented
43 0 ▶ return undef unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
44 0 my $res = $_[0];
45 0 my $i = 0;
46 0 ▶ while (++$i < @_) { $res = $_[$i] if $_[$i] > $res }
Branch: 2 branches
BranchTrueFalseTotal
if (++$i < @_) 0 0 0
if $_[$i] > $res 0 0 0
47 0 $res;
48 }
49 # END_BLOCK: max
50  
51 # return highest top-index from all rows in case they're different lengths
52 0 ▶sub _max_array_index {
Subroutine _max_array_index: not called CC=1 SCAR=6.9
53 0 my $rows = shift;
54 0 return max( map { $#$_ } @$rows );
55 }
56  
57 1 1;
58 # ABSTRACT: Generate TSV
59  
60 __END__
↑ Summary