CSVUtils/csv_check_field_names.pm

filter: Statementstmt 58.6% 17 / 29 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 51.2% 21 / 41 CC 5 SCAR 27.5
CC
5
Cov
49%
__ANON__
30.0
__ANON__
2.0
BEGIN
1.0
CRAP 15.6
« CSVUtils/csv_fill_cells.pm ↑ Summary CSVUtils/csv_pick_rows.pm »
1 package App::CSVUtils::csv_check_field_names;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 1 our $DATE = '2026-07-09'; # DATE
9 1 our $DIST = 'App-CSVUtils'; # DIST
10 1 our $VERSION = '1.038'; # VERSION
11  
12 1 ▶use App::CSVUtils qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 gen_csv_util
14 1 );
15  
16 gen_csv_util(
17 name => 'csv_check_field_names',
18 summary => 'Check field names',
19 description => <<'MARKDOWN',
20  
21 This utility performs the following checks:
22  
23 - There is at least 1 field;
24 - There is no duplicate field name;
25 - There is no field name of '' (empty string);
26  
27 There will be options to add some additional checks in the future.
28  
29 MARKDOWN
30 add_args => {
31 },
32 links => [
33 {url=>'prog:csv-check-cell-values', summary=>'Check of the values of individual cells'},
34 ],
35 tags => ['category:checking'],
36  
37 examples => [
38 {
39 summary => 'Check that all field names are valid',
40 argv => ['file.csv'],
41 test => 0,
42 'x.doc.show_result' => 0,
43 },
44 ],
45  
46 writes_csv => 0,
47  
48 0 ▶ on_input_header_row => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
49 0 my $r = shift;
50  
51 0 ▶ die [400, "There must at least be 1 field"] unless @{ $r->{input_fields} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$r->{"input_fields"};} 0 0 0
52  
53 0 my %seen;
54 0 my $i = 0;
55 0 for my $field (@{ $r->{input_fields} }) {
56 0 $i++;
57 0 ▶ die [400, "There is a field (#$i) with empty name"] unless length $field;
Branch: 1 branch
BranchTrueFalseTotal
unless length $field 0 0 0
58 0 ▶ die [400, "There is duplicate field (#$i, $field)"] if $seen{$field}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$field}++ 0 0 0
59 }
60 },
61  
62 0 ▶ on_input_data_row => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 my $r = shift;
64 0 $r->{wants_skip_files}++;
65 },
66 1 );
67  
68 1 1;
69 # ABSTRACT: Check field names
70  
71 __END__
« CSVUtils/csv_fill_cells.pm ↑ Summary CSVUtils/csv_pick_rows.pm »