App-CSVUtils
view release on metacpan or search on metacpan
* "input_data_row_count", int. Contains the number of actual data rows
that have read. Will be reset for each CSV file.
If you are outputting CSV ("writes_csv" gen argument set to true), the
following keys will be available:
* "output_emitter", a Text::CSV_XS instance for output.
* "output_fields", array of str. Should be set to list of output field
names. If unset, will be set to be the same as "input_fields".
* "output_fields_idx", hash with field names as keys and field indexes
(0-based integer) as values. Normally you do not need to set this
manually; you just need to set "output_fields" and this hash will be
computed automatically for you just before the first output row is
outputted.
* "output_filenames", array of str.
* "output_filename", str, name of current output file.
* "output_filenum", uint, the number of the current output file, 1
being the first file, 2 for the second, and so on.
* "output_fh", handle to the current output file.
* "output_rownum", uint. The number of rows that have been outputted
(reset after each output file).
* "output_data_rownum", uint. The number of data rows that have been
outputted (reset after each output file). This will be equal to
"input_rownum" less 1 if input file has header.
For other hook-specific keys, see the documentation for associated hook
point.
*ACCEPTING ADDITIONAL COMMAND-LINE OPTIONS/ARGUMENTS*
As mentioned above, you will get additional command-line
options/arguments in "$r->{util_args}" hashref. Some options/arguments
are already added by "gen_csv_util", e.g. "input_filename" or
"input_filenames" along with "input_sep_char", etc (when your utility
declares "reads_csv"), "output_filename" or "output_filenames" along
with "overwrite", "output_sep_char", etc (when your utility declares
"writes_csv").
If you want to accept additional arguments/options, you specify them in
"add_args" (hashref, with key being Each option/argument has to be
specified first via "add_args" (as hashref, with key being argument name
and value the argument specification as defined in Rinci::function)).
Some argument specifications have been defined in App::CSVUtils and can
be used. See existing utilities for examples.
*READING CSV DATA*
To read CSV data, normally your utility would provide handler for the
"on_input_data_row" hook and sometimes additionally
"on_input_header_row".
*OUTPUTTING STRING OR RETURNING RESULT*
To output string, usually you call the provided routine
"$r->{code_print}". This routine will open the output files for you.
You can also return enveloped result directly by setting "$r->{result}".
*OUTPUTTING CSV DATA*
To output CSV data, usually you call the provided routine
"$r->{code_print_row}". This routine accepts a row (arrayref or
hashref). This routine will open the output files for you when needed,
as well as print header row automatically.
You can also buffer rows from input to e.g. "$r->{output_rows}", then
call "$r->{code_print_row}" repeatedly in the "after_read_input" hook to
print all the rows.
*READING MULTIPLE CSV FILES*
To read multiple CSV files, you first specify "reads_multiple_csv".
Then, you can supply handler for "on_input_header_row" and
"on_input_data_row" as usual. If you want to do something before/after
each input file, you can also supply handler for
"before_open_input_file" or "after_close_input_file".
*WRITING TO MULTIPLE CSV FILES*
Similarly, to write to many CSv files, you first specify
"writes_multiple_csv". Then, you can supply handler for
"on_input_header_row" and "on_input_data_row" as usual. To switch to the
next file, set "$r->{wants_switch_to_next_output_file}" to true, in
which case the next call to "$r->{code_print_row}" will close the
current file and open the next file.
*CHANGING THE OUTPUT FIELDS*
When calling "$r->{code_print_row}", you can output whatever fields you
want. By convention, you can set "$r->{output_fields}" and
"$r->{output_fields_idx}" to let other handlers know about the output
fields. For example, see the implementation of csv-concat.
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
* add_args => *hash*
(No description)
* add_args_rels => *hash*
(No description)
* add_meta_props => *hash*
Add additional Rinci function metadata properties.
* after_close_input_file => *code*
(No description)
* after_close_input_files => *code*
(No description)
* after_read_input => *code*
(No description)
* before_open_input_file => *code*
(No description)
* before_open_input_files => *code*
(No description)
* before_read_input => *code*
(No description)
* description => *str*
(No description)
* examples => *array*
(No description)
* links => *array[hash]*
(No description)
* name* => *perl::identifier::unqualified_ascii*
( run in 0.514 second using v1.01-cache-2.11-cpan-39bf76dae61 )