Flux::In - input stream interface
version 1.03
# How to use objects implementing this role $line = $in->read; $chunk = $in->read_chunk($limit); $in->commit;
Flux::In is a role which every reading stream must implement.
Flux::In
Consumers must implement read, read_chunk and commit methods.
read
read_chunk
commit
# How to consume this role use Moo; with "Flux::In"; has counter => ( is => "ro", default => sub { 0 }, ); sub read { my ($self) = @_; my $counter = $self->counter; $self->counter($counter + 1); return "Line $counter"; } sub read_chunk { my ($self, $limit) = @_; my $counter = $self->counter; $self->counter($counter + $limit); return [ $counter .. $counter + $limit - 1 ]; } sub commit { say "commiting position"; }
Get the next item from the stream.
Returns undef when there's no data left.
Get the new chunk with items. Chunk is an arrayref with items, ordered as if read() was invoked several times.
read()
$limit is a recommendation. Most input streams respect it and return exactly this number of items in chunk, but some don't. So if you get a chunk with 1 item when you asked for 5, don't treat it as a sign that you don't need to read further. Read until you get an undef or an empty chunk.
$limit
Commit input stream's position.
Generally, successful commit means that you can restart your program and continue from the same position next time. Although some streams don't support position at all, for example, array_in from Stream::Simple.
array_in
Stream's author should make sure that stream is still readable after this.
Flux::In::Role::Easy - specialization of this role for those who don't want to bother with 3 methods, and want to just implement read().
Flux::In::Role::Lag - role for input streams which are aware of their lag.
Vyacheslav Matyukhin <me@berekuk.ru>
This software is copyright (c) 2013 by Yandex LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Flux, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Flux
CPAN shell
perl -MCPAN -e shell install Flux
For more information on module installation, please visit the detailed CPAN module installation guide.