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