| 1 | package Catmandu::Exporter::CSV; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 7 | our $VERSION = '1.2025'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Text::CSV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 7 | with 'Catmandu::TabularExporter'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 7 | has csv => (is => 'lazy'); | |||||||||||||||||||||||||||
| 14 | 16 | ▶ | has quote_char => (is => 'ro', default => sub {'"'}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 16 | ▶ | has escape_char => (is => 'ro', default => sub {'"'}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 7 | has always_quote => (is => 'ro'); | |||||||||||||||||||||||||||
| 17 | 7 | has quote_space => (is => 'ro'); | |||||||||||||||||||||||||||
| 18 | has sep_char => ( | ||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | 14 | ▶ | default => sub {','}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 21 | ▶ | coerce => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 22 | 21 | my $sep_char = $_[0]; | |||||||||||||||||||||||||||
| 23 | 0 | $sep_char =~ s/(\\[abefnrt])/"qq{$1}"/gee; | |||||||||||||||||||||||||||
| 24 | 21 | return $sep_char; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 7 | ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 17 | ▶ | sub _build_csv { | ||||||||||||||||||||||||||
|
Subroutine
_build_csv: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 29 | 17 | my ($self) = @_; | |||||||||||||||||||||||||||
| 30 | 17 | ▶ | Text::CSV->new( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | binary => 1, | ||||||||||||||||||||||||||||
| 33 | eol => "\n", | ||||||||||||||||||||||||||||
| 34 | sep_char => $self->sep_char, | ||||||||||||||||||||||||||||
| 35 | always_quote => $self->always_quote, | ||||||||||||||||||||||||||||
| 36 | quote_space => $self->quote_space, | ||||||||||||||||||||||||||||
| 37 | quote_char => $self->quote_char ? $self->quote_char : undef, | ||||||||||||||||||||||||||||
| 38 | escape_char => $self->escape_char ? $self->escape_char : undef, | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 34 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 34 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 45 | 34 | my $fields = $self->fields; | |||||||||||||||||||||||||||
| 46 | my $row = [ | ||||||||||||||||||||||||||||
| 47 | map { | ||||||||||||||||||||||||||||
| 48 | 34 | ▶ | my $val = $data->{$_} // ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$data->{$_} // ""
MC/DC100%1/1
$data->{$_} // ""
$data->{$_}
Truth table100%2/2
A
A= $data->{$_}
| |||||||||||||||||||||||||||||
| 49 | 56 | $val =~ s/\t/\\t/g; | |||||||||||||||||||||||||||
| 50 | 56 | $val =~ s/\n/\\n/g; | |||||||||||||||||||||||||||
| 51 | 56 | $val =~ s/\r/\\r/g; | |||||||||||||||||||||||||||
| 52 | 56 | $val; | |||||||||||||||||||||||||||
| 53 | } @$fields | ||||||||||||||||||||||||||||
| 54 | ]; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 34 | $self->_print_header; | |||||||||||||||||||||||||||
| 57 | 34 | $self->csv->print($self->fh, $row); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 12 | ▶ | sub commit { | ||||||||||||||||||||||||||
|
Subroutine
commit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # ensure header gets printed even if there are no records | ||||||||||||||||||||||||||||
| 64 | 12 | $self->_print_header; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 46 | ▶ | sub _print_header { | ||||||||||||||||||||||||||
|
Subroutine
_print_header: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 68 | 46 | my ($self) = @_; | |||||||||||||||||||||||||||
| 69 | 46 | ▶ | if (!$self->count && $self->header) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->count and $self->header
MC/DC100%2/2
not $self->count and $self->header
not $self->count
$self->header
Truth table100%3/3
not(A) and B
A= not $self->countB= $self->header
| |||||||||||||||||||||||||||||
| 70 | 16 | ▶ | my $row = $self->columns || $self->fields; | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->columns || $self->fields
MC/DC100%2/2
$self->columns || $self->fields
$self->columns
$self->fields
Truth table100%3/3
A || B
A= $self->columnsB= $self->fields
| |||||||||||||||||||||||||||||
| 71 | 16 | ▶ | $self->csv->print($self->fh, $row) if $row && @$row; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$row and @$row
MC/DC50%1/2
$row and @$row
$row
@$row
Truth table66%2/3
A and B
A= $rowB= @$row
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 7 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||