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