blib/lib/Net/Async/Tangence/Protocol.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 87.5% 7 / 8 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 96.6% 57 / 59 CC 6 SCAR 7.7
CC
6
Cov
96%
__ANON__
4.1
configure
2.0
_init
2.0
CRAP 2.2
« Build ↑ Summary blib/lib/Net/Async/Tangence.pm »
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
l!l
45
MC/DC100%1/1
$params->{"on_closed"} ||= undef
$params->{"on_closed"}
Truth table100%2/2
A
A= $params->{"on_closed"}
Aresult
11
00
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
BranchTrueFalseTotal
if (exists $params{"on_closed"}) 9 6 15
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
BranchTrueFalseTotal
if $on_closed 2 1 3
52  
53 3 $self->tangence_closed;
54  
55 3 ▶ if( my $parent = $self->parent ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $parent = $self->parent) { } 0 3 3
elsif (my $loop = $self->get_loop) { } 1 2 3
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;
« Build ↑ Summary blib/lib/Net/Async/Tangence.pm »