Simple/Channel.pm

filter: Statementstmt 76.6% 46 / 60 Branchbran 100% 4 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 10 totaltotal 69.8% 65 / 93 CC 5 SCAR 5.8
CC
5
Cov
79%
flush
3.0
DESTROY
2.0
shutdown
2.0
CRAP 1.8
« scratch.pl ↑ Summary Simple/Message.pm »
1 package IPC::Simple::Channel;
2 4 $IPC::Simple::Channel::VERSION = '0.08';
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 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub new {
9 6 ▶ my ($class) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10  
11 6 bless{
12 waiters => [],
13 buffer => [],
14 is_shutdown => 0,
15 }, $class;
16 }
17  
18 sub DESTROY {
19 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=1 SCAR=6.9
20 0 $self->shutdown;
21 }
22  
23 sub shutdown {
24 4 ▶ my $self = shift;
Subroutine shutdown: called CC=2 SCAR=6.9
Pod undocumented
25  
26 4 $self->{is_shutdown} = 1;
27  
28 # flush any remaining messages that have pending receivers
29 4 $self->flush;
30  
31 # send undef to any remaining receivers
32 4 $_->send for @{ $self->{waiters} };
33 }
34  
35 sub size {
36 0 ▶ my $self = shift;
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
37 0 return scalar @{ $self->{buffer} };
38 }
39  
40 sub put {
41 6 ▶ my $self = shift;
Subroutine put: called CC=1 SCAR=0.0
Pod undocumented
42 6 push @{ $self->{buffer} }, @_;
43 6 $self->flush;
44 6 return $self->{size};
45 }
46  
47 sub get {
48 2 ▶ my $self = shift;
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
49 2 $self->async->recv;
50 }
51  
52 sub recv {
53 5 ▶ my $self = shift;
Subroutine recv: called CC=1 SCAR=0.0
Pod undocumented
54 5 $self->async->recv;
55 }
56  
57 sub next {
58 0 ▶ my $self = shift;
Subroutine next: not called CC=1 SCAR=6.9
Pod undocumented
59 0 $self->async->recv;
60 }
61  
62 sub async {
63 7 ▶ my $self = shift;
Subroutine async: called CC=2 SCAR=6.9
Pod undocumented
64 7 my $cv = AnyEvent->condvar;
65  
66 7 ▶ if ($self->{is_shutdown}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'is_shutdown'}) { } 1 6 7
67 1 my $msg = shift @{ $self->{buffer} };
68 1 $cv->send($msg);
69 1 return $cv;
70 }
71 else {
72 6 push @{ $self->{waiters} }, $cv;
73 6 $self->flush;
74 6 return $cv;
75 }
76 }
77  
78 sub flush {
79 16 ▶ my $self = shift;
Subroutine flush: called CC=3 SCAR=11.0
Pod undocumented
80 16 ▶ while (@{ $self->{waiters} } && @{ $self->{buffer} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"waiters"};} and @{$self->{"buffer"};}) 6 16 22
Condition100%3/3
@{$self->{"waiters"};} and @{$self->{"buffer"};}
!ll&&!rl&&r
976
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
81 6 my $cv = shift @{ $self->{waiters} };
82 6 $cv->send( shift @{ $self->{buffer} } );
83 }
84 }
85  
86 sub clear {
87 0 ▶ my $self = shift;
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
88 0 $self->flush;
89 0 my @msgs = @{ $self->{buffer} };
90 0 $self->{buffer} = [];
91 0 $self->{size} = 0;
92 0 return @msgs;
93 }
94  
95 4 1;
96  
97 __END__
« scratch.pl ↑ Summary Simple/Message.pm »