CSVUtils/csv_sort_fields_by_example.pm

filter: Statementstmt 89.2% 25 / 28 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 88.8% 32 / 36 CC 1 SCAR 1.2
CC
1
Cov
89%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« CSVUtils/csv_sort_fields_by_spec.pm ↑ Summary CSVUtils/csv_csv.pm »
1 package App::CSVUtils::csv_sort_fields_by_example;
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;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use App::CSVUtils::csv_sort_fields;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Perinci::Sub::Util qw(gen_modified_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 my $res = gen_modified_sub(
17 output_name => 'csv_sort_fields_by_example',
18 base_name => 'App::CSVUtils::csv_sort_fields::csv_sort_fields',
19 summary => 'Sort CSV fields by example',
20 description => <<'MARKDOWN',
21  
22 This is a thin wrapper for <prog:csv-sort-fields>, which can already sort fields
23 by example but you have to specify it as a series of `--by-example` options:
24  
25 % csv-sort-fields in.csv --by-example c --by-example g --by-example d
26  
27 This utility allows you to say:
28  
29 % csv-sort-fields-by-example in.csv c g d
30  
31 Example:
32  
33 # in.csv
34 a,b,c,d,e,f,g
35 1,2,3,4,5,6,7
36  
37 % csv-sort-fields-by-example in.csv c g d
38 c,g,d,a,b,e,f
39 3,7,4,1,2,5,6
40  
41 MARKDOWN
42 remove_args => ['by_examples', 'by_code', 'by_sortsub'],
43 add_args => {
44 fields => {
45 'x.name.is_plural' => 1,
46 'x.name.singular' => 'field',
47 summary => 'Fields for examples',
48 'summary.alt.plurality.singular' => 'Add field for example',
49 schema => ['array*', of=>'str*'],
50 req => 1,
51 pos => 1,
52 slurpy => 1,
53 cmdline_aliases => {f=>{}},
54 completion => \&App::CSVUtils::_complete_field,
55 },
56 },
57 modify_args => {
58 1 ▶ output_filename => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
59 1 my $argspec = shift;
60 1 delete $argspec->{pos};
61 },
62 },
63 tags => ['category:sorting'],
64 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 0 my %args = @_;
66 0 my $examples = delete $args{fields};
67 0 App::CSVUtils::csv_sort_fields::csv_sort_fields(
68 %args,
69 by_examples => $examples,
70 );
71 },
72 1 );
73  
74 1 1;
75 # ABSTRACT: Sort CSV fields by example
76  
77 __END__
« CSVUtils/csv_sort_fields_by_spec.pm ↑ Summary CSVUtils/csv_csv.pm »