| 1 | package Spreadsheet::Wright::CSV; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | no warnings qw( uninitialized numeric ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | $Spreadsheet::Wright::CSV::VERSION = '0.107'; | |||||||||||||||||||||||||||
| 10 | 1 | $Spreadsheet::Wright::CSV::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Text::CSV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use parent qw(Spreadsheet::Wright); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub new | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 1 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 22 | 1 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | $self->{'_FILENAME'} = $args{'file'} // $args{'filename'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"file"} // $args{"filename"}
MC/DC0%0/2
$args{"file"} // $args{"filename"}
$args{"file"}
$args{"filename"}
Truth table33%1/3
A // B
A= $args{"file"}B= $args{"filename"}
| |||||||||||||||||||||||||||||
| 25 | or croak "Need filename"; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | $args{'csv_options'}{'eol'} //= "\r\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"csv_options"}{"eol"} //= "\r\n"
MC/DC0%0/1
$args{"csv_options"}{"eol"} //= "\r\n"
$args{"csv_options"}{"eol"}
Truth table50%1/2
A
A= $args{"csv_options"}{"eol"}
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | $args{'csv_options'}{'sep_char'} //= ","; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"csv_options"}{"sep_char"} //= ","
MC/DC0%0/1
$args{"csv_options"}{"sep_char"} //= ","
$args{"csv_options"}{"sep_char"}
Truth table50%1/2
A
A= $args{"csv_options"}{"sep_char"}
| |||||||||||||||||||||||||||||
| 29 | 1 | $self->{'_CSV_OPTIONS'} = $args{'csv_options'}; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub _prepare | ||||||||||||||||||||||||||||
| 35 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_prepare: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 36 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 3 | ▶ | $self->{'_CSV_OBJ'} //=Text::CSV->new($self->{'_CSV_OPTIONS'}); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_CSV_OBJ"} //= "Text::CSV"->new($self->{"_CSV_OPTIONS"})
MC/DC0%0/2
$self->{"_CSV_OBJ"} //= "Text::CSV"->new($self->{"_CSV_OPTIONS"})
$self->{"_CSV_OBJ"}
"Text::CSV"->new($self->{"_CSV_OPTIONS"})
Truth table66%2/3
A //= B
A= $self->{"_CSV_OBJ"}B= "Text::CSV"->new($self->{"_CSV_OPTIONS"})
| |||||||||||||||||||||||||||||
| 38 | 3 | return $self; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub close | ||||||||||||||||||||||||||||
| 42 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 2 | my $self=shift; | |||||||||||||||||||||||||||
| 44 | 2 | ▶ | return if $self->{'_CLOSED'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | $self->{'_FH'}->close if $self->{'_FH'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 1 | $self->{'_CLOSED'}=1; | |||||||||||||||||||||||||||
| 47 | 1 | return $self; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub _add_prepared_row | ||||||||||||||||||||||||||||
| 51 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_add_prepared_row: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||
| 52 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | my @texts; | |||||||||||||||||||||||||||
| 55 | 3 | foreach (@_) | |||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 6 | my $content = $_->{'content'}; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | $content = sprintf($content, $_->{'sprintf'}) | ||||||||||||||||||||||||||||
| 60 | 6 | ▶ | if $_->{'sprintf'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # Hide non-ASCII characters from Unicode-unaware Text::CSV. | ||||||||||||||||||||||||||||
| 63 | 0 | $content =~ s/([^\x20-\x7e]|[\r\&\n\t])/sprintf('&#%d;', ord($1))/esg; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 6 | push @texts, $content; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 3 | my $string; | |||||||||||||||||||||||||||
| 69 | $self->{'_CSV_OBJ'}->combine(@texts) | ||||||||||||||||||||||||||||
| 70 | 3 | ▶ | or croak "csv_combine failed at ".$self->{'_CSV_OBJ'}->error_input(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 3 | $string = $self->{'_CSV_OBJ'}->string(); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Restore non-ASCII characters. | ||||||||||||||||||||||||||||
| 74 | 0 | $string =~ s/&#(\d+);/chr($1)/esg; | |||||||||||||||||||||||||||
| 75 | 3 | ▶ | $string = Encode::decode('utf8',$string) unless Encode::is_utf8($string); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 3 | ▶ | $string = Encode::encode(($self->{'_ENCODING'}//'utf8'), $string); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_ENCODING"} // "utf8"
MC/DC0%0/1
$self->{"_ENCODING"} // "utf8"
$self->{"_ENCODING"}
Truth table50%1/2
A
A= $self->{"_ENCODING"}
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Output to file. | ||||||||||||||||||||||||||||
| 79 | 3 | $self->{'_FH'}->print($string); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 3 | return $self; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | 1; | |||||||||||||||||||||||||||