line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TableDataRole::Util::CSV; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1188
|
use 5.010001; |
|
2
|
|
|
|
|
6
|
|
4
|
2
|
|
|
2
|
|
23
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
39
|
|
5
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
73
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use Role::Tiny; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
10
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
10
|
|
|
|
|
|
|
our $DATE = '2022-02-20'; # DATE |
11
|
|
|
|
|
|
|
our $DIST = 'TableDataRoles-Standard'; # DIST |
12
|
|
|
|
|
|
|
our $VERSION = '0.014'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
requires 'get_column_names'; |
15
|
|
|
|
|
|
|
requires 'has_next_item'; |
16
|
|
|
|
|
|
|
requires 'get_next_item'; |
17
|
|
|
|
|
|
|
requires 'reset_iterator'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub as_csv { |
20
|
2
|
|
|
2
|
1
|
2326
|
require Text::CSV_XS; |
21
|
2
|
|
|
|
|
9097
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
66
|
|
|
30
|
$self->{csv_parser} //= Text::CSV_XS->new({binary=>1}); |
24
|
2
|
|
|
|
|
96
|
my $csv = $self->{csv_parser}; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
14
|
$self->reset_iterator; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
3
|
my $res = ""; |
29
|
2
|
|
|
|
|
15
|
$csv->combine($self->get_column_names); |
30
|
2
|
|
|
|
|
46
|
$res .= $csv->string . "\n"; |
31
|
2
|
|
|
|
|
22
|
while ($self->has_next_item) { |
32
|
8
|
|
|
|
|
23
|
my $row = $self->get_next_item; |
33
|
8
|
|
|
|
|
18
|
$csv->combine(@$row); |
34
|
8
|
|
|
|
|
84
|
$res .= $csv->string . "\n"; |
35
|
|
|
|
|
|
|
} |
36
|
2
|
|
|
|
|
13
|
$res; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
# ABSTRACT: Provide as_csv() and other CSV-related methods |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |