Data::Tubes::Plugin::Reader
This module contains factory functions to generate tubes that ease reading of input records.
Each of the generated tubes has the following contract:
the input record MUST be a hash reference;
depending on the presence of an argument input, the record itself or the sub-hash indicated by input MUST contain a field fh with a filehandle. By default, the input field is set to source;
input
fh
source
one field in the hash (according to factory argument output, set to raw by default) is set to the output of the reading operation.
output
raw
The factory functions below have two names, one starting with read_ and the other without this prefix. They are perfectly equivalent to each other, whereas the short version can be handier e.g. when using tube or pipeline from Data::Tubes.
read_
tube
pipeline
This is a simple wrapper around "read_by_separator", where the separator argument is forced to be a newline \n.
separator
\n
This is a simple wrapper around "read_by_separator", where the separator argument is forced to be the empty string.
my $tube = by_record_reader(%args); # OR my $tube = by_record_reader(\%args);
read inputs according to a record reader subroutine.
Accepted arguments are:
emit_eof
when an end-of-file is hit, emit a record with the output field set to undef, so that this condition will be visible in the tubes on the downstream;
undef
identification
you don't normally need to use this... so look at the code in case you have to;
name of the input field in the record. If defined and not empty, it points to a sub-hash that will contain a filehandle field fh; otherwise, this fh field MUST be contained directly in the input record contents. Defaults to source;
name
name of the tube, for easier debugging;
name of the output field. The output record is ALWAYS a hash reference, containing the input record and the output correponding to this key. Defaults to c<raw>;
record_reader
a sub reference that takes a filehandle as the only input parameter, and returns whatever is read.
my $tube = by_separator(%args); # OR my $tube = by_separator(\%args);
read inputs setting a separator string (a-la INPUT_RECORD_SEPARATOR, see perlvar).
INPUT_RECORD_SEPARATOR
chomp
apply the chomp function before emitting what's read;
a separator string to set as INPUT_RECORD_SEPARATOR, see perlvar.
Report bugs either through RT or GitHub (patches welcome).
Flavio Poletti <polettix@cpan.org>
Copyright (C) 2016 by Flavio Poletti <polettix@cpan.org>
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Data::Tubes, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Tubes
CPAN shell
perl -MCPAN -e shell install Data::Tubes
For more information on module installation, please visit the detailed CPAN module installation guide.