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