| 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
| |||||||||||
| 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
| |||||||||||
| 38 | 4 | $quote = 1; | |||||||||
| 39 | } | ||||||||||
| 40 | 11 | ▶ | if ($cell_data =~ /"/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 4 | $cell_data =~ s/"/""/g; | |||||||||
| 42 | 4 | $quote = 1; | |||||||||
| 43 | } | ||||||||||
| 44 | 11 | ▶ | if ($quote) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||