Concurrent/Runner/Select.pm

filter: Statementstmt 31.1% 14 / 45 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 25.7% 18 / 70 CC 12 SCAR 44.6
CC
12
Cov
23%
run
132.0
new
6.0
BEGIN
1.0
CRAP 86.4
↑ Summary Concurrent/Actor.pm »
1 package IO::Concurrent::Runner::Select;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $Carp::Internal{+__PACKAGE__}++;
9  
10 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
11 0 my ($class, $contexts, $opts) = @_;
12 0 ▶ $opts ||= {};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
13  
14 0 bless {
15 %$opts,
16 contexts => $contexts,
17 } => $class;
18 }
19  
20 0 ▶sub run {
Subroutine run: not called CC=11 SCAR=48.8
Pod undocumented
21 0 my $self = shift;
22  
23 0 my %context_map = map { $_->handler->fileno => $_ } @{ $self->{contexts} };
24  
25 0 my @aborted_contexts;
26 0 ▶ while (%context_map) {
Branch: 1 branch
BranchTrueFalseTotal
if (%context_map) 0 0 0
27 0 my ($readable, $writable) = do {
28 0 my @readers = map { $_->handler } grep { $_->current_actor->is_waiting_for_readable } values %context_map;
29 0 my @writers = map { $_->handler } grep { $_->current_actor->is_waiting_for_writable } values %context_map;
30 0 IO::Select->select(
31 IO::Select->new(@readers),
32 IO::Select->new(@writers),
33 undef,
34 0
35 )
36 };
37  
38 0 ▶ if (defined $writable) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $writable) 0 0 0
39 0 my @writable_context = @context_map{map $_->fileno, @$writable};
40 0 for my $context (@writable_context) {
41 0 $context->current_actor->callback->($context);
42 0 ▶ push @aborted_contexts => $context if $context->error;
Branch: 1 branch
BranchTrueFalseTotal
if $context->error 0 0 0
43 0 ▶ delete $context_map{$context->handler->fileno} if $context->is_completed;
Branch: 1 branch
BranchTrueFalseTotal
if $context->is_completed 0 0 0
44 }
45 }
46  
47 0 ▶ if (defined $readable) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $readable) 0 0 0
48 0 my @readable_context = @context_map{map $_->fileno, @$readable};
49 0 for my $context (@readable_context) {
50 0 $context->current_actor->callback->($context);
51 0 ▶ push @aborted_contexts => $context if $context->error;
Branch: 1 branch
BranchTrueFalseTotal
if $context->error 0 0 0
52 0 ▶ delete $context_map{$context->handler->fileno} if $context->is_completed;
Branch: 1 branch
BranchTrueFalseTotal
if $context->is_completed 0 0 0
53 }
54 }
55 }
56  
57 0 for my $context (@aborted_contexts) {
58 0 $self->{on_error}->($context);
59 }
60 }
61  
62 1 1;
63 __END__
↑ Summary Concurrent/Actor.pm »