15 Jan 2022 06:44:58 UTC
- Distribution: Data-Tubes
- Module version: 0.740
- Source (raw)
- Pod Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (272 / 0 / 0)
- KwaliteeBus factor: 1
- 83.80% Coverage
- License: artistic_2
- Perl: v5.10.0
- Activity24 month
- Download (141.47KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- BUGS AND LIMITATIONS
- COPYRIGHT AND LICENSE
This module contains factory functions to generate tubes that ease handling data sources.
my $tube = iterate_array($array, %args); # OR my $tube = iterate_array(%args); # OR my $tube = iterate_array(\%args);
iterate over an array, that can be provided to the factory as an
arrayfield or unnamed first parameter
$array, or provided as input record. In case both are provided, the array from the factory (the global array) is iterated for each call to the tube, before the array provided to the tube call itself.
The input record for the generated tube MUST be either false or a reference to an array. The returned tube ALWAYS returns an iterator (i.e. it returns the string
iterator, followed by a sub reference that acts as an iterator).
The following arguments are supported:
the global array to iterate over. Defaults to an empty array reference. It can be passed also as the first unnamed argument;
name of the tube, useful when debugging;
my $tube = open_file($binmode, %args); # OR my $tube = open_file(%args); # OR my $tube = open_file(\%args);
open a file from the input record.
Depending on what is provided as parameter
%args, the input channel will be either the record itself (if
inputis undefined or zero-length) or what
inputpoints inside the input record, that in this case MUST be a hash.
The input channel might be either a filehandle or a string; in either case,
normalize_filenamefrom Data::Tubes::Util is used to resolve a handle or a filename.
The tube returns a data structure that copies the input one (if
inputis defined and not empty) and sets an
outputfield (set in the factory, defaults to
source) to a hash reference with the following fields:
a filehandle that can be used to read from the source;
what was passed as input;
the type of the particular source, might be
scalar(if the input is a reference to a scalar) or
a name that will provide a hint about what the channel is. If the input channel is a handle, this will be set to
%sexpanded to a string); if it is a reference to a scalar (which is a valid filename for
CORE::open) it sets it to
scalar:%sand if it is a plain filename it sets it to
The arguments accepted by the factory function are the following:
whenever a filehandle is opened, the generated filehandle is set to this via
CORE::binmode. Defaults to
:encoding(UTF-8). This parameter can also be passed as the first unnamed argument in the call to the factory function;
if defined and not empty, the records input to the tube MUST be hash references with a field named as the provided
input; otherwise, the whole input record is the channel to open;
name for the tube, useful for debugging;
name of the output field in the returned record, defaults to
my $tube = iterate_files(@channels_list); # OR my $tube = iterate_files(@channels_list, \%args);
generate a tube that iterates over a list of files, either provided to the factory function directly, or provided as a reference to an array when invoking the tube. The two following cases are equivalent:
# pass the file list to the factory my $tube1 = iterate_files('foo.txt', 'bar.txt'); my (undef, $iterator) = $tube1->(); # leave factory without list, pass to the tube my $tube2 = iterate_files(); my (undef, $iterator)= $tube2->(['foo.txt', 'bar.txt']);
All elements in
@channels_listMUST be valid channels for the tube generated by "open_file". Optionally, the last item in the argument list can be a reference to a hash, with further options for the factory.
The following arguments can be (optionally) supplied via
optional hash with arguments for "iterate_array", where the
arrayfield is overridden with
optional hash with arguments for
loggerin Data::Tubes::Plugin::Plubming. Defaults to setting a
targetpointing to a sub reference that gives out message
reading from %s, where
%sis expanded with the content of
Report bugs either through RT or GitHub (patches welcome).
Flavio Poletti <email@example.com>
Copyright (C) 2016 by Flavio Poletti <firstname.lastname@example.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.