Simple/Channel.pm

filter: Statementstmt 89.6% 52 / 58 Branchbran 75.0% 3 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 7 totaltotal 82.9% 73 / 88 CC 5 SCAR 4.9
CC
5
Cov
89%
flush
3.0
async
2.2
DEMOLISH
2.0
CRAP 1.6
« Simple.pm ↑ Summary Simple/Message.pm »
1 package IPC::Simple::Channel;
2 4 $IPC::Simple::Channel::VERSION = '0.03';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 has waiters =>
11 is => 'ro',
12 isa => ArrayRef[InstanceOf['AnyEvent::CondVar']],
13 4 ▶ default => sub{ [] };
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 has buffer =>
16 is => 'ro',
17 isa => ArrayRef,
18 4 ▶ default => sub{ [] };
Subroutine __ANON__: called CC=1 SCAR=0.0
19  
20 4 has is_shutdown =>
21 is => 'rw',
22 isa => Bool,
23 default => 0;
24  
25 sub DEMOLISH {
26 0 ▶ my $self = shift;
Subroutine DEMOLISH: not called CC=1 SCAR=6.9
Pod undocumented
27 0 $self->shutdown;
28 }
29  
30 sub shutdown {
31 4 ▶ my $self = shift;
Subroutine shutdown: called CC=2 SCAR=6.9
Pod undocumented
32  
33 4 $self->is_shutdown(1);
34  
35 # flush any remaining messages that have pending receivers
36 4 $self->flush;
37  
38 # send undef to any remaining receivers
39 4 $_->send for @{ $self->waiters };
40 }
41  
42 sub size {
43 8 ▶ my $self = shift;
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
44 8 return scalar @{ $self->buffer };
45 }
46  
47 sub put {
48 8 ▶ my $self = shift;
Subroutine put: called CC=1 SCAR=0.0
Pod undocumented
49 8 push @{ $self->buffer }, @_;
50 8 $self->flush;
51 8 return $self->size;
52 }
53  
54 sub get {
55 2 ▶ my $self = shift;
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
56 2 $self->async->recv;
57 }
58  
59 sub async {
60 3 ▶ my $self = shift;
Subroutine async: called CC=2 SCAR=8.0
Pod undocumented
61 3 my $cv = AnyEvent->condvar;
62  
63 3 ▶ if ($self->is_shutdown) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_shutdown) { } 0 3 3
64 0 my $msg = shift @{ $self->buffer };
65 0 $cv->send($msg);
66 0 return $cv;
67 }
68 else {
69 3 push @{ $self->waiters }, $cv;
70 3 $self->flush;
71 3 return $cv;
72 }
73 }
74  
75 sub flush {
76 15 ▶ my $self = shift;
Subroutine flush: called CC=3 SCAR=11.0
Pod undocumented
77 15 ▶ while (@{ $self->waiters } && @{ $self->buffer }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->waiters;} and @{$self->buffer;}) 3 15 18
Condition100%3/3
@{$self->waiters;} and @{$self->buffer;}
!ll&&!rl&&r
1323
MC/DC100%2/2
@{$self->waiters;} and @{$self->buffer;}
@{$self->waiters;} @{$self->buffer;}
Truth table100%3/3
A and B
A= @{$self->waiters;}B= @{$self->buffer;}
ABresult
0X0
100
111
78 3 my $cv = shift @{ $self->waiters };
79 3 $cv->send( shift @{ $self->buffer } );
80 }
81 }
82  
83 4 1;
84  
85 __END__
« Simple.pm ↑ Summary Simple/Message.pm »