MooX-Async-Console
view release on metacpan or search on metacpan
lib/MooX/Async/Console/TCPClient.pm view on Meta::CPAN
package MooX::Async::Console::TCPClient;
=head1 NAME
MooX::Async::Console::TCPClient - TCP client interaction for MooX::Async::Console
=head1 SYNOPSIS
See L<MooX::Async::Console>
=head1 DESCRIPTION
A L<IO::Async::Stream> subclass which waits for a complete line of
text and invokes L</on_line>.
=head1 BUGS
Certainly.
=cut
use Modern::Perl '2017';
use strictures 2;
use Moo;
use MooX::Async;
use namespace::clean;
extends MooXAsync('Stream');
with 'MooX::Role::Logger';
=head1 ATTRIBUTES
=over
=item id
A string composed from L</address> and L</port> which identifies this
client.
=cut
has id => is => lazy => init_arg => undef, builder =>
sub { sprintf 'tcp:%s:%s', $_[0]->address, $_[0]->port };
=item address
The IP address this client connected from.
=cut
has address => is => lazy => init_arg => undef, builder =>
sub { $_[0]->read_handle->peerhost }; # TODO: Force normalised ipv6
=item port
The TCP port this client connected from.
=cut
has port => is => lazy => init_arg => undef, builder =>
sub { $_[0]->read_handle->peerport };
=back
=head1 METHODS
=over
=item flush
Flush the client's write buffer.
=cut
sub flush { $_[0]->write('')->get }
=item say
Write the arguments to the stream with C<\n> appended.
( run in 0.731 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )