| 1 | package App::CSVUtils::csv2td; | ||
| 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(gen_csv_util); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | gen_csv_util( | ||
| 15 | name => 'csv2td', | ||
| 16 | summary => 'Return an enveloped aoaos table data from CSV data', | ||
| 17 | description => <<'MARKDOWN', | ||
| 18 | |||
| 19 | Read more about "table data" in <pm:App::td>, which comes with a CLI <prog:td> | ||
| 20 | to munge table data. | ||
| 21 | |||
| 22 | MARKDOWN | ||
| 23 | add_args => { | ||
| 24 | }, | ||
| 25 | tags => ['category:converting','outputs-data-structure'], | ||
| 26 | |||
| 27 | examples => [ | ||
| 28 | { | ||
| 29 | summary => 'Convert to table data then use the "td" utility to grab the first 5 rows', | ||
| 30 | src => '[[prog]] file.csv --json | td head -n5', | ||
| 31 | src_plang => 'bash', | ||
| 32 | test => 0, | ||
| 33 | 'x.doc.show_result' => 0, | ||
| 34 | }, | ||
| 35 | ], | ||
| 36 | |||
| 37 | 0 | ▶ | on_input_header_row => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 38 | 0 | my $r = shift; | |
| 39 | |||
| 40 | 0 | $r->{result} = [200, "OK", [], {'table.fields' => $r->{input_fields}}]; | |
| 41 | }, | ||
| 42 | |||
| 43 | 0 | ▶ | on_input_data_row => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 44 | 0 | my $r = shift; | |
| 45 | |||
| 46 | 0 | push @{ $r->{result}[2] }, $r->{input_row}; | |
| 47 | }, | ||
| 48 | |||
| 49 | 1 | writes_csv => 0, | |
| 50 | ); | ||
| 51 | |||
| 52 | 1 | 1; | |
| 53 | # ABSTRACT: Return an enveloped aoaos table data from CSV data | ||
| 54 | |||
| 55 | __END__ | ||