NAME
Mojo::IOLoop::LineReader
VERSION
version 0.3
SYNOPSIS
use Mojo::IOLoop::LineReader;
# Create reader
my $reader = Mojo::IOLoop::LineReader->new($handle);
$reader->on(readln => sub {
my ($reader, $line) = @_;
...
});
$reader->on(close => sub {
my $reader = shift;
...
});
$reader->on(error => sub {
my ($reader, $err) = @_;
...
});
# Start and stop watching for new data
$reader->start;
$reader->stop;
# Start reactor if necessary
$reader->reactor->start unless $reader->reactor->is_running;
DESCRIPTION
Mojo::IOLoop::LineReader is a subclass of Mojo::IOLoop::Stream that implements reading from a handle line by line.
NAME
Mojo::IOLoop::LineReader - Non-blocking line-oriented input stream
EVENTS
Mojo::IOLoop::LineReader inherits all events from Mojo::IOLoop::Stream and can emit the following new ones.
readln
$reader->on(readln => sub {
my ($reader, $line) = @_;
...
});
When data arrives on the stream, it is broken down into lines. This event is emitted for each such line.
ATTRIBUTES
Mojo::IOLoop::LineReader inherits all attributes from Mojo::IOLoop::Stream and implements the following new ones.
input_record_separator
my $rs = $reader->input_record_separator;
$reader = $reader->input_record_separator("");
Line separator to use when breaking input to lines, defaults to the value of $/
at construction time.
METHODS
Mojo::IOLoop::LineReader inherits all methods from Mojo::IOLoop::Stream and implements the following new ones.
new
my $reader = Mojo::IOLoop::LineReader->new($handle);
Construct a new Mojo::IOLoop::LineReader object and subscribe to "read" in Mojo::IOLoop::Stream and "close" in Mojo::IOLoop::Stream events with special handlers.
SEE ALSO
Mojo::IOLoop::Stream, MojoX::LineStream.
ACKNOWLEDGEMENTS
Jan Henning Thorsen and Joel Berger for advice and code on #mojo.
The development of this library has been partially sponsored by Connectivity, Inc.
AUTHOR
Adriano Ferreira <ferreira@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Adriano Ferreira.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.