line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
93789
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Catmandu::Exporter::CSV; |
7
|
1
|
|
|
1
|
|
345
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
9
|
1
|
|
|
1
|
|
304
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
10
|
|
|
|
|
|
|
has sep_char => (is => 'ro', default => sub {"\t"},); |
11
|
|
|
|
|
|
|
has csv => (is => 'lazy', handles => [qw(add)]); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'Catmandu::TabularExporter'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my ($self) = @_; |
16
|
|
|
|
|
|
|
my $csv = Catmandu::Exporter::CSV->new( |
17
|
5
|
|
|
5
|
|
137
|
header => $self->header, |
18
|
5
|
|
|
|
|
108
|
collect_fields => $self->collect_fields, |
19
|
|
|
|
|
|
|
sep_char => $self->sep_char, |
20
|
|
|
|
|
|
|
quote_char => undef, |
21
|
|
|
|
|
|
|
escape_char => undef, |
22
|
|
|
|
|
|
|
file => $self->file, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
$csv->{fields} = $self->fields; |
25
|
|
|
|
|
|
|
$csv->{columns} = $self->columns; |
26
|
5
|
|
|
|
|
42
|
$csv; |
27
|
5
|
|
|
|
|
12
|
} |
28
|
5
|
|
|
|
|
67
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=pod |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Catmandu::Exporter::TSV - a tab-delimited TSV exporter |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SYNOPSIS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# From the command line |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$ catmandu convert JSON to TSV --fields "id,title,year" < data.json |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# In a Perl script |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use Catmandu; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $exporter = Catmandu->exporter( |
49
|
|
|
|
|
|
|
'TSV', |
50
|
|
|
|
|
|
|
fix => 'myfix.txt', |
51
|
|
|
|
|
|
|
fields => "f1,f2,f3", |
52
|
|
|
|
|
|
|
header => 1); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $exporter = Catmandu->exporter( |
55
|
|
|
|
|
|
|
'TSV', |
56
|
|
|
|
|
|
|
fields => [qw(f1 f2 f3)]); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$exporter->add_many($arrayref); |
59
|
|
|
|
|
|
|
$exporter->add_many($iterator); |
60
|
|
|
|
|
|
|
$exporter->add_many(sub { }); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$exporter->add($hashref); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
printf "exported %d items\n" , $exporter->count; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 DESCRIPTION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This C<Catmandu::Exporter> exports items as rows with tab-separated values |
69
|
|
|
|
|
|
|
(TSV). A header line with field names will be included if option C<header> is |
70
|
|
|
|
|
|
|
set. See L<Catmandu::TabularExporter> on how to configure the field mapping |
71
|
|
|
|
|
|
|
and column names. Newlines and tabulator values in field values are escaped |
72
|
|
|
|
|
|
|
as C<\n>, C<\r>, and C<\t>. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 CONFIGURATION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=over |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item file |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Write output to a local file given by its path or file handle. Alternatively a |
81
|
|
|
|
|
|
|
scalar reference can be passed to write to a string and a code reference can be |
82
|
|
|
|
|
|
|
used to write to a callback function. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item fh |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Write the output to an L<IO::Handle>. If not specified, |
87
|
|
|
|
|
|
|
L<Catmandu::Util::io|Catmandu::Util/IO-functions> is used to create the output |
88
|
|
|
|
|
|
|
handle from the C<file> argument or by using STDOUT. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item fix |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
An ARRAY of one or more fixes or file scripts to be applied to exported items. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item encoding |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Binmode of the output stream C<fh>. Set to "C<:utf8>" by default. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item fields |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
See L<Catmandu::TabularExporter>. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item columns |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
See L<Catmandu::TabularExporter>. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item header |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Include a header line with column names. Enabled by default. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item sep_char |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Column separator (C<tab> by default) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
See L<Catmandu::TabularExporter>, L<Catmandu::Exporter>, L<Catmandu::Addable>, |
119
|
|
|
|
|
|
|
L<Catmandu::Fixable>, L<Catmandu::Counter>, and L<Catmandu::Logger> for a full |
120
|
|
|
|
|
|
|
list of methods. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SEE ALSO |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L<Catmandu::Importer::TSV> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |