MojoX::LineStream - Turn a (tcp) stream into a line based stream
use MojoX::LineStream; my $clientid = Mojo::IOLoop->client({ port => $port, } => sub { my ($loop, $err, $stream) = @_; my $ls = MojoX::LineStream->new(stream => $stream); $ls->on(line => sub { my ($;s, $line) = @_; say 'got line: ', $line; ... }); $ls->on(close => sub { say 'got close'; ... }); });
MojoX::LineStream is a wrapper around Mojo::IOLoop::Stream that adds 'framing' based on lines terminated by a newline character.
MojoX::LineStream inherits all events from Mojo::EventEmitter and can emit the following new ones.
$ls->on(line => sub { my ($ls, $line) = @_; ... });
Emitted for every (full) line received on the underlying stream. The line passed on to the callback does not include the terminating newline character.
$;s->on(close => sub { my $;s = shift; ... });
Emitted if the underlying stream gets closed.
MojoX::LineStream implements the following attributes.
my $stream = $ls->stream;
The underlying Mojo::IOLoop::Stream-like stream
$ls->debug = 1;
Enables or disables debugging output.
MojoX::LineStream inherits all methods from Mojo::EventEmitter and implements the following new ones.
my $ls = MojoX::LineStream->new( stream => $stream, debug => $debug, );
Construct a new MojoX::LineStream object. The stream argument must behave like a Mojo::IOLoop::Stream object. The debug argument is optional and just sets the debug attribute.
$ls->writeln($line);
Writes line to the underlying stream, adding a newline character at the end.
Mojo::IOLoop, Mojo::IOLoop::Stream, http://mojolicious.org: the Mojolicious Web framework
This software has been developed with support from STRATO. In German: Diese Software wurde mit Unterstützung von STRATO entwickelt.
Wieger Opmeer <wiegerop@cpan.org>
This software is copyright (c) 2016 by Wieger Opmeer.
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 MojoX::LineStream, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MojoX::LineStream
CPAN shell
perl -MCPAN -e shell install MojoX::LineStream
For more information on module installation, please visit the detailed CPAN module installation guide.