CSVUtils/csv_list_field_names.pm

filter: Statementstmt 100% 22 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 27 / 27 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« CSVUtils/csv_csv.pm ↑ Summary CSVUtils/csv_sorted_fields.pm »
1 package App::CSVUtils::csv_list_field_names;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 2 our $DATE = '2026-07-09'; # DATE
9 2 our $DIST = 'App-CSVUtils'; # DIST
10 2 our $VERSION = '1.038'; # VERSION
11  
12 2 ▶use App::CSVUtils qw(gen_csv_util);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 gen_csv_util(
15 name => 'csv_list_field_names',
16 summary => 'List field names of CSV file',
17 description => <<'MARKDOWN',
18  
19 MARKDOWN
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 1 ▶ on_input_header_row => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 1 my $r = shift;
45  
46 $r->{result} = [
47 200,
48 "OK", [
49 3 map { {name=>$_, index=>$r->{input_fields_idx}{$_}+1} }
50 1 sort keys %{$r->{input_fields_idx}}
51 ],
52 {'table.fields'=>['name','index']},
53 ];
54 1 $r->{wants_skip_files}++;
55 }
56 2 );
57  
58 2 1;
59 # ABSTRACT: List field names of CSV file
60  
61 __END__
« CSVUtils/csv_csv.pm ↑ Summary CSVUtils/csv_sorted_fields.pm »