| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Spreadsheet::Wright::CSV; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18
|
use 5.010; |
|
|
1
|
|
|
|
|
4
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
41
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
6
|
1
|
|
|
1
|
|
5
|
no warnings qw( uninitialized numeric ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
56
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
|
9
|
1
|
|
|
1
|
|
3
|
$Spreadsheet::Wright::CSV::VERSION = '0.106'; |
|
10
|
1
|
|
|
|
|
27
|
$Spreadsheet::Wright::CSV::AUTHORITY = 'cpan:TOBYINK'; |
|
11
|
|
|
|
|
|
|
} |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
66
|
|
|
14
|
1
|
|
|
1
|
|
552
|
use Encode; |
|
|
1
|
|
|
|
|
15070
|
|
|
|
1
|
|
|
|
|
78
|
|
|
15
|
1
|
|
|
1
|
|
725
|
use Text::CSV; |
|
|
1
|
|
|
|
|
13594
|
|
|
|
1
|
|
|
|
|
47
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
7
|
use parent qw(Spreadsheet::Wright); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
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
|
|
|
9
|
$self->{'_FILENAME'} = $args{'file'} // $args{'filename'} |
|
25
|
|
|
|
|
|
|
or croak "Need filename"; |
|
26
|
|
|
|
|
|
|
|
|
27
|
1
|
|
50
|
|
|
4
|
$args{'csv_options'}{'eol'} //= "\r\n"; |
|
28
|
1
|
|
50
|
|
|
6
|
$args{'csv_options'}{'sep_char'} //= ","; |
|
29
|
1
|
|
|
|
|
2
|
$self->{'_CSV_OPTIONS'} = $args{'csv_options'}; |
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
4
|
return $self; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _prepare |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
3
|
|
|
3
|
|
5
|
my $self = shift; |
|
37
|
3
|
|
66
|
|
|
13
|
$self->{'_CSV_OBJ'} //=Text::CSV->new($self->{'_CSV_OPTIONS'}); |
|
38
|
3
|
|
|
|
|
163
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub close |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
2
|
|
|
2
|
1
|
6
|
my $self=shift; |
|
44
|
2
|
100
|
|
|
|
215
|
return if $self->{'_CLOSED'}; |
|
45
|
1
|
50
|
|
|
|
6
|
$self->{'_FH'}->close if $self->{'_FH'}; |
|
46
|
1
|
|
|
|
|
114
|
$self->{'_CLOSED'}=1; |
|
47
|
1
|
|
|
|
|
3
|
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
|
|
|
|
|
8
|
my $content = $_->{'content'}; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$content = sprintf($content, $_->{'sprintf'}) |
|
60
|
6
|
50
|
|
|
|
14
|
if $_->{'sprintf'}; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Hide non-ASCII characters from Unicode-unaware Text::CSV. |
|
63
|
6
|
|
|
|
|
22
|
$content =~ s/([^\x20-\x7e]|[\r\&\n\t])/sprintf('&#%d;', ord($1))/esg; |
|
|
0
|
|
|
|
|
0
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
6
|
|
|
|
|
12
|
push @texts, $content; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
4
|
my $string; |
|
69
|
|
|
|
|
|
|
$self->{'_CSV_OBJ'}->combine(@texts) |
|
70
|
3
|
50
|
|
|
|
11
|
or croak "csv_combine failed at ".$self->{'_CSV_OBJ'}->error_input(); |
|
71
|
3
|
|
|
|
|
68
|
$string = $self->{'_CSV_OBJ'}->string(); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Restore non-ASCII characters. |
|
74
|
3
|
|
|
|
|
22
|
$string =~ s/&#(\d+);/chr($1)/esg; |
|
|
0
|
|
|
|
|
0
|
|
|
75
|
3
|
50
|
|
|
|
20
|
$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
|
|
|
|
|
52
|
$self->{'_FH'}->print($string); |
|
80
|
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
28
|
return $self; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |