File Coverage

blib/lib/Data/Tabular/Output/CSV.pm
Criterion Covered Total %
statement 35 37 94.5
branch 8 10 80.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 48 53 90.5


line stmt bran cond sub pod time code
1             # Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved
2              
3 1     1   6 use strict;
  1         2  
  1         62  
4              
5             package Data::Tabular::Output::CSV;
6              
7 1     1   5 use base "Data::Tabular::Output";
  1         2  
  1         605  
8              
9 1     1   6 use overload 'eq' => \&_eq;
  1         2  
  1         7  
10              
11             sub _eq
12             {
13 1     1   257 my ($a, $b, $x) = @_;
14              
15 1 50       4 if ($x) {
16 1         4 $a->text eq $b;
17             } else {
18 0         0 $a eq $b->text;
19             }
20             }
21              
22             sub text
23             {
24 1     1 0 2 my $self = shift;
25 1         1 my $ret = "\n";
26              
27 1         8 my $output = $self->output;
28              
29              
30 1         6 for my $row ($self->rows()) {
31 5         7 my @table;
32 5         20 for my $cell ($row->cells($output->headers)) {
33 11         32 my $cell_data = $cell->html_string;
34 11         13 my $width = 20; # $cell->width;
35 11         29 $cell_data =~ s/^\s*(.*)\s*$/$1/;
36 11         37 my $quote;
37 11 100       46 if ($cell_data =~ /,/) {
38 4         7 $quote = 1;
39             }
40 11 100       29 if ($cell_data =~ /"/) {
41 4         14 $cell_data =~ s/"/""/g;
42 4         10 $quote = 1;
43             }
44 11 100       24 if ($quote) {
45 5         9 $cell_data = '"' . $cell_data . '"';
46             }
47 11         50 push(@table, $cell_data);
48 11         20 my $length = $width - length($cell_data);
49 11 50       33 if ($length <=0) {
50 0         0 $length = 1;
51             }
52             }
53 5         30 $ret .= join(',', @table);
54 5         13 $ret .= "\n";
55             }
56              
57 1         17 $ret;
58             }
59              
60             1;
61             __END__