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