1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
# You may distribute under the terms of either the GNU General Public License
# or the Artistic License (the same terms as Perl itself)
#
# (C) Paul Evans, 2010-2011 -- leonerd@leonerd.org.uk
package Net::Async::Tangence::Protocol 0.16;
use v5.14;
use warnings;
use base qw( IO::Async::Stream Tangence::Stream );
use Carp;
=head1 NAME
C<Net::Async::Tangence::Protocol> - concrete implementation of
C<Tangence::Stream> for C<IO::Async>
=head1 DESCRIPTION
This subclass of L<IO::Async::Stream> provides a concrete implementation of
the L<Tangence::Stream> mixin. It is not intended to be directly used by
server implementations. Instead, it is subclassed as
L<Net::Async::Tangence::Client> and L<Net::Async::Tangence::ServerProtocol>.
=cut
sub _init
{
my $self = shift;
my ( $params ) = @_;
$self->SUPER::_init( $params );
$params->{on_closed} ||= undef;
}
sub configure
{
my $self = shift;
my %params = @_;
if( exists $params{on_closed} ) {
my $on_closed = delete $params{on_closed};
$params{on_closed} = sub {
my ( $self ) = @_;
$on_closed->( $self ) if $on_closed;
$self->tangence_closed;
if( my $parent = $self->parent ) {
$parent->remove_child( $self );
}
elsif( my $loop = $self->get_loop ) {
$loop->remove( $self );
}
};
}
$self->SUPER::configure( %params );
}
sub tangence_write
{
my $self = shift;
$self->write( $_[0] );
}
sub on_read
{
my $self = shift;
my ( $buffref, $closed ) = @_;
$self->tangence_readfrom( $$buffref );
return 0;
}
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
=cut
0x55AA;
|