Async/Chain.pm

filter: Statementstmt 93.9% 62 / 66 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.1% 16 / 17 Podpod 85.7% 6 / 7 totaltotal 92.8% 91 / 98 CC 6 SCAR 5.7
CC
6
Cov
93%
_wait
4.0
join
2.0
daemonize
2.0
CRAP 1.8
« Async/Task.pm ↑ Summary Async.pm »
1 package Parallel::Async::Chain;
2 41 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 41 ▶use Class::Accessor::Lite rw => [qw/tasks/];
Subroutine BEGIN: called CC=1 SCAR=0.0
7 41 ▶use POSIX ":sys_wait_h";
Subroutine BEGIN: called CC=1 SCAR=0.0
8 41 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 63 ▶sub join :method {
Subroutine join: called CC=2 SCAR=6.9
Pod documented
11 63 my $self = shift;
12 63 ▶ $self = bless +{ tasks => [] } => $self unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 40 23 63
13  
14 63 push @{ $self->{tasks} } => @_;
15  
16 63 return $self;
17 }
18  
19 44 ▶sub recv :method {
Subroutine recv: called CC=1 SCAR=0.0
Pod documented
20 44 my ($self, @args) = @_;
21  
22 41 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 44 local $Parallel::Async::Task::WANTARRAY = 1;
24 41 ▶ use warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 44 my @pids = $self->run(@args);
27 26 $self->_wait(@pids);
28  
29 26 return $self->read_child_result();
30 }
31  
32 61 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod documented
33 61 my ($self, @args) = @_;
34 61 return map { $_->run(@args) } @{ $self->{tasks} };
35 }
36  
37 0 ▶sub daemonize {
Subroutine daemonize: not called CC=1 SCAR=6.9
Pod documented
38 0 my ($self, @args) = @_;
39 0 return map { $_->daemonize(@args) } @{ $self->{tasks} };
40 }
41  
42 26 ▶sub _wait {
Subroutine _wait: called CC=4 SCAR=13.9
43 26 my $self = shift;
44 26 my %pids = map { $_ => 1 } @_;
45  
46 26 ▶ while (%pids) {
Branch: 1 branch
BranchTrueFalseTotal
if (%pids) 259 26 285
47 259 my $pid = waitpid(-1, WNOHANG);
48 259 ▶ last if $pid == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $pid == -1 0 259 259
49  
50 259 ▶ delete $pids{$pid} if exists $pids{$pid};
Branch: 1 branch
BranchTrueFalseTotal
if exists $pids{$pid} 81 178 259
51 }
52 continue {
53 41 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
54 259 Time::HiRes::usleep($Parallel::Async::Task::WAIT_INTERVAL);
55 }
56 }
57  
58 27 ▶sub read_child_result {
Subroutine read_child_result: called CC=1 SCAR=0.0
Pod undocumented
59 27 my $self = shift;
60 27 return map { $_->read_child_result() } @{ $self->{tasks} };
61 }
62  
63 24 ▶sub reset :method {
Subroutine reset: called CC=2 SCAR=6.9
Pod documented
64 24 my $self = shift;
65 24 $_->reset for @{ $self->{tasks} };
66 24 return $self;
67 }
68  
69 17 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
70 17 my $self = shift;
71 17 my $class = ref $self;
72 17 return $class->join(map { $_->clone } @{ $self->{tasks} });
73 }
74  
75 41 1;
76 __END__
« Async/Task.pm ↑ Summary Async.pm »