=pod =for vim vim: tw=72 ts=3 sts=3 sw=3 et ai : =encoding utf8 =head1 NAME Data::Tubes::Plugin::Reader =head1 DESCRIPTION This module contains factory functions to generate I that ease reading of input records. Each of the generated tubes has the following contract: =over =item * the input record MUST be a hash reference; =item * depending on the presence of an argument C, the record itself or the sub-hash indicated by C MUST contain a field C with a filehandle. By default, the C field is set to C; =item * one field in the hash (according to factory argument C, set to C by default) is set to the output of the reading operation. =back The factory functions below have two names, one starting with C and the other without this prefix. They are perfectly equivalent to each other, whereas the short version can be handier e.g. when using C or C from L. =head1 FUNCTIONS =head2 B<< by_line >> This is a simple wrapper around L, where the C argument is forced to be a newline C<\n>. =head2 B<< by_paragraph >> This is a simple wrapper around L, where the C argument is forced to be the empty string. =head2 B<< by_record_reader >> my $tube = by_record_reader($record_reader, %args); # OR my $tube = by_record_reader(%args); # OR my $tube = by_record_reader(\%args); read inputs according to a I subroutine. Accepted arguments are: =over =item C when an end-of-file is hit, emit a record with the output field set to C, so that this condition will be visible in the tubes on the downstream; =item C you don't normally need to use this... so look at the code in case you have to; =item C 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 C; otherwise, this C field MUST be contained directly in the input record contents. Defaults to C; =item C name of the tube, for easier debugging; =item C 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; =item C a sub reference that takes a filehandle as the only input parameter, and returns whatever is read. This is the I
parameter, so it can also be provided as the first unnamed argument when calling this factory function. It has no default and is required. =back =head2 B<< by_separator >> my $tube = by_separator($separator, %args); # OR my $tube = by_separator(%args); # OR my $tube = by_separator(\%args); read inputs setting a separator string (a-la C, see L). Accepted arguments are: =over =item C apply the C function before emitting what's read. Defaults to a I value; =item C when an end-of-file is hit, emit a record with the output field set to C, so that this condition will be visible in the tubes on the downstream. Defaults to a I value; =item C you don't normally need to use this... so look at the code in case you have to; =item C 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 C; otherwise, this C field MUST be contained directly in the input record contents. Defaults to C; =item C name of the tube, for easier debugging; =item C 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; =item C a separator string to set as C, see L. This parameter defaults to C. It is the I
parameter, so it can also be provided as the first unnamed argument when calling this factory function. =back =head2 B<< read_by_line >> Alias for L. =head2 B<< read_by_paragraph >> Alias for L. =head2 B<< read_by_record_reader >> Alias for L. =head2 B<< read_by_separator >> Alias for L. =head1 BUGS AND LIMITATIONS Report bugs either through RT or GitHub (patches welcome). =head1 AUTHOR Flavio Poletti =head1 COPYRIGHT AND LICENSE Copyright (C) 2016 by Flavio Poletti 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. =cut