IO::Async::Protocol::LineStream - stream-based protocols using lines of text
IO::Async::Protocol::LineStream
Most likely this class will be subclassed to implement a particular network protocol.
package Net::Async::HelloWorld; use strict; use warnings; use base qw( IO::Async::Protocol::LineStream ); sub on_read_line { my $self = shift; my ( $line ) = @_; if( $line =~ m/^HELLO (.*)/ ) { my $name = $1; $self->invoke_event( on_hello => $name ); } } sub send_hello { my $self = shift; my ( $name ) = @_; $self->write_line( "HELLO $name" ); }
This small example elides such details as error handling, which a real protocol implementation would be likely to contain.
The following events are invoked, either using subclass methods or CODE references in parameters:
Invoked when a new complete line of input is received.
The following named parameters may be passed to new or configure:
new
configure
CODE reference for the on_read_line event.
on_read_line
Writes a line of text to the transport stream. The text will have the end-of-line marker appended to it; $text should not end with it.
$text
Paul Evans <leonerd@leonerd.org.uk>
To install IO::Async, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IO::Async
CPAN shell
perl -MCPAN -e shell install IO::Async
For more information on module installation, please visit the detailed CPAN module installation guide.