Tabular/Output/CSV.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 90.7% 49 / 54 CC 8 SCAR 15.5
CC
8
Cov
92%
text
7.0
_eq
2.1
BEGIN
1.0
CRAP 4.7
« Tabular/Row/Averages.pm ↑ Summary Tabular/Row/Data.pm »
1 # Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Data::Tabular::Output::CSV;
6  
7 1 ▶use base "Data::Tabular::Output";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use overload 'eq' => \&_eq;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub _eq
12 1 ▶{
Subroutine _eq: called CC=2 SCAR=7.6
13 1 my ($a, $b, $x) = @_;
14  
15 1 ▶ if ($x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x) { } 1 0 1
16 1 $a->text eq $b;
17 } else {
18 0 $a eq $b->text;
19 }
20 }
21  
22 sub text
23 1 ▶{
Subroutine text: called CC=7 SCAR=19.5
Pod undocumented
24 1 my $self = shift;
25 1 my $ret = "\n";
26  
27 1 my $output = $self->output;
28  
29  
30 1 for my $row ($self->rows()) {
31 5 my @table;
32 5 for my $cell ($row->cells($output->headers)) {
33 11 my $cell_data = $cell->html_string;
34 11 my $width = 20; # $cell->width;
35 11 $cell_data =~ s/^\s*(.*)\s*$/$1/;
36 11 my $quote;
37 11 ▶ if ($cell_data =~ /,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cell_data =~ /,/) 4 7 11
38 4 $quote = 1;
39 }
40 11 ▶ if ($cell_data =~ /"/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cell_data =~ /"/) 4 7 11
41 4 $cell_data =~ s/"/""/g;
42 4 $quote = 1;
43 }
44 11 ▶ if ($quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote) 5 6 11
45 5 $cell_data = '"' . $cell_data . '"';
46 }
47 11 push(@table, $cell_data);
48 11 my $length = $width - length($cell_data);
49 11 ▶ if ($length <=0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length <= 0) 0 11 11
50 0 $length = 1;
51 }
52 }
53 5 $ret .= join(',', @table);
54 5 $ret .= "\n";
55 }
56  
57 1 $ret;
58 }
59  
60 1 1;
61 __END__
« Tabular/Row/Averages.pm ↑ Summary Tabular/Row/Data.pm »