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