line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::CSVUtils::csv_list_field_names; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7832
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
8
|
|
|
|
|
|
|
our $DATE = '2023-07-25'; # DATE |
9
|
|
|
|
|
|
|
our $DIST = 'App-CSVUtils'; # DIST |
10
|
|
|
|
|
|
|
our $VERSION = '1.030'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use App::CSVUtils qw(gen_csv_util); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
230
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
gen_csv_util( |
15
|
|
|
|
|
|
|
name => 'csv_list_field_names', |
16
|
|
|
|
|
|
|
summary => 'List field names of CSV file', |
17
|
|
|
|
|
|
|
description => <<'_', |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
_ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
add_args => { |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
examples => [ |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
summary => 'List field names of a CSV as a text table of name and position', |
27
|
|
|
|
|
|
|
argv => ['file.csv'], |
28
|
|
|
|
|
|
|
test => 0, |
29
|
|
|
|
|
|
|
'x.doc.show_result' => 0, |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
summary => 'List field names of a CSV as tab-separated lines, sort by name', |
33
|
|
|
|
|
|
|
src => '[[prog]] file.csv | sort', |
34
|
|
|
|
|
|
|
test => 0, |
35
|
|
|
|
|
|
|
'x.doc.show_result' => 0, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
], |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
writes_csv => 0, |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
tags => ['category:information'], |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
on_input_header_row => sub { |
44
|
|
|
|
|
|
|
my $r = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$r->{result} = [ |
47
|
|
|
|
|
|
|
200, |
48
|
|
|
|
|
|
|
"OK", [ |
49
|
|
|
|
|
|
|
map { {name=>$_, index=>$r->{input_fields_idx}{$_}+1} } |
50
|
|
|
|
|
|
|
sort keys %{$r->{input_fields_idx}} |
51
|
|
|
|
|
|
|
], |
52
|
|
|
|
|
|
|
{'table.fields'=>['name','index']}, |
53
|
|
|
|
|
|
|
]; |
54
|
|
|
|
|
|
|
$r->{wants_skip_files}++; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
# ABSTRACT: List field names of CSV file |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=encoding UTF-8 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 NAME |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
App::CSVUtils::csv_list_field_names - List field names of CSV file |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 VERSION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This document describes version 1.030 of App::CSVUtils::csv_list_field_names (from Perl distribution App-CSVUtils), released on 2023-07-25. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 FUNCTIONS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 csv_list_field_names |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Usage: |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
csv_list_field_names(%args) -> [$status_code, $reason, $payload, \%result_meta] |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
List field names of CSV file. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Examples: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item * List field names of a CSV as a text table of name and position: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
csv_list_field_names(input_filename => "file.csv"); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This function is not exported. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Arguments ('*' denotes required arguments): |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over 4 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * B<input_escape_char> => I<str> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Specify character to escape value in field in input CSV, will be passed to Text::CSV_XS. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Defaults to C<\\> (backslash). Overrides C<--input-tsv> option. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * B<input_filename> => I<filename> (default: "-") |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Input CSV file. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Use C<-> to read from stdin. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Encoding of input file is assumed to be UTF-8. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * B<input_header> => I<bool> (default: 1) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Specify whether input CSV has a header row. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
By default, the first row of the input CSV will be assumed to contain field |
121
|
|
|
|
|
|
|
names (and the second row contains the first data row). When you declare that |
122
|
|
|
|
|
|
|
input CSV does not have header row (C<--no-input-header>), the first row of the |
123
|
|
|
|
|
|
|
CSV is assumed to contain the first data row. Fields will be named C<field1>, |
124
|
|
|
|
|
|
|
C<field2>, and so on. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * B<input_quote_char> => I<str> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Specify field quote character in input CSV, will be passed to Text::CSV_XS. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Defaults to C<"> (double quote). Overrides C<--input-tsv> option. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * B<input_sep_char> => I<str> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Specify field separator character in input CSV, will be passed to Text::CSV_XS. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Defaults to C<,> (comma). Overrides C<--input-tsv> option. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * B<input_tsv> => I<true> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Inform that input file is in TSV (tab-separated) format instead of CSV. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Overriden by C<--input-sep-char>, C<--input-quote-char>, C<--input-escape-char> |
143
|
|
|
|
|
|
|
options. If one of those options is specified, then C<--input-tsv> will be |
144
|
|
|
|
|
|
|
ignored. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=back |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Returns an enveloped result (an array). |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
First element ($status_code) is an integer containing HTTP-like status code |
152
|
|
|
|
|
|
|
(200 means OK, 4xx caller error, 5xx function error). Second element |
153
|
|
|
|
|
|
|
($reason) is a string containing error message, or something like "OK" if status is |
154
|
|
|
|
|
|
|
200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth |
155
|
|
|
|
|
|
|
element (%result_meta) is called result metadata and is optional, a hash |
156
|
|
|
|
|
|
|
that contains extra information, much like how HTTP response headers provide additional metadata. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Return value: (any) |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 HOMEPAGE |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/App-CSVUtils>. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 SOURCE |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-App-CSVUtils>. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 CONTRIBUTING |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
To contribute, you can send patches by email/via RT, or send pull requests on |
176
|
|
|
|
|
|
|
GitHub. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Most of the time, you don't need to build the distribution yourself. You can |
179
|
|
|
|
|
|
|
simply modify the code, then test via: |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
% prove -l |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
If you want to build the distribution (e.g. to try to install it locally on your |
184
|
|
|
|
|
|
|
system), you can install L<Dist::Zilla>, |
185
|
|
|
|
|
|
|
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>, |
186
|
|
|
|
|
|
|
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other |
187
|
|
|
|
|
|
|
Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond |
188
|
|
|
|
|
|
|
that are considered a bug and can be reported to me. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This software is copyright (c) 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016 by perlancar <perlancar@cpan.org>. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
195
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 BUGS |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-CSVUtils> |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
202
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
203
|
|
|
|
|
|
|
feature. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |