MojoX::NetstringStream - Turn a (tcp) stream into a NetstringStream
use MojoX::NetstringStream; my $clientid = Mojo::IOLoop->client({ port => $port, } => sub { my ($loop, $err, $stream) = @_; my $ns = MojoX::NetstringStream->new(stream => $stream); $ns->on(chunk => sub { my ($ns, $chunk) = @_; say 'got chunk: ', $chunk; ... }); $ns->on(close => sub { say 'got close'; ... }); });
MojoX::NetstringStream is a wrapper around Mojo::IOLoop::Stream that adds framing using the netstring encoding.
The underlying Mojo::IOLoop stream to use for reading and writing
Enables debugging
Maximum size of the accepted netstring frames, if set. A nserr event is raised when a oversized frame is received.
Default: none
MojoX::NetstringStream inherits all events from Mojo::EventEmitter and can emit the following new ones.
$ns->on(chunk => sub { my ($ns, $chunk) = @_; ... });
Emitted for every (full) netstring received on the underlying stream.
$ns->on(close => sub { my $ns = shift; ... });
Emitted if the underlying stream gets closed.
$ns->on(nserr => sub { my ($ns, $err) = @_; ... });
Emitted if there was some kind of framing error, currenty either a missing ',' at the end or a oversized frame.
MojoX::NetstringStream implements the following attributes.
my $stream = $ns->stream;
The underlying Mojo::IOLoop::Stream-like stream
$ls->debug = 1;
Enables or disables debugging output.
MojoX::NetstringStream inherits all methods from Mojo::EventEmitter and implements the following new ones.
my $ns = MojoX::NetstringStream->new( stream => $stream, debug => $debug, );
Construct a new MojoX::NetstringStream object. The stream argument must behave like a Mojo::IOLoop::Stream object. The debug argument is optional and just sets the debug attribute.
$ns->write($chunk);
Writes chunk to the underlying stream as a netstring.
Mojo::IOLoop, Mojo::IOLoop::Stream, http://mojolicious.org: the Mojolicious Web framework
https://cr.yp.to/proto/netstrings.txt: netstrings specification.
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) 2017 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::NetstringStream, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MojoX::NetstringStream
CPAN shell
perl -MCPAN -e shell install MojoX::NetstringStream
For more information on module installation, please visit the detailed CPAN module installation guide.