| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
@{$self->waiters;} and @{$self->buffer;}
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;}
| |||||||||||||||||||||||||||||
| 78 | 3 | my $cv = shift @{ $self->waiters }; | |||||||||||||||||||||||||||
| 79 | 3 | $cv->send( shift @{ $self->buffer } ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | 1; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||