blib/lib/Parallel/ForkManager/Segmented.pm

filter: Statementstmt 100% 38 / 38 Branchbran 68.7% 11 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 91.8% 56 / 61 SCAR 22.0
CC
9
Cov
91%
run
9.2
BEGIN
1.0
BEGIN
1.0
CRAP 9.1
↑ Summary Build »
1 package Parallel::ForkManager::Segmented;
2 22 $Parallel::ForkManager::Segmented::VERSION = '0.8.0';
3 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 ▶use parent 'Parallel::ForkManager::Segmented::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 22 ▶use Parallel::ForkManager ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub run
12 {
13 21 ▶ my ( $self, $args ) = @_;
Subroutine run: called CC=9 SCAR=22.2
Pod documented
14  
15 21 my $processed = $self->process_args($args);
16 21 ▶ return if not $processed;
Branch: 1 branch
BranchTrueFalseTotal
unless $processed 1 20 21
17 my ( $WITH_PM, $batch_cb, $batch_size, $nproc, $stream_cb, ) =
18 20 @{$processed}{qw/ WITH_PM batch_cb batch_size nproc stream_cb /};
19  
20 20 my $pm;
21  
22 20 ▶ if ($WITH_PM)
Branch: 1 branch
BranchTrueFalseTotal
if ($WITH_PM) 20 0 20
23 {
24 20 $pm = Parallel::ForkManager->new($nproc);
25 }
26 20 my $batch = $stream_cb->( { size => 1 } )->{items};
27 20 ▶ return if not defined $batch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $batch 0 20 20
28 20 $batch_cb->($batch);
29 ITEMS:
30 20 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if (defined($batch = &$stream_cb({"size", $batch_size})->{"items"})) 56 4 60
31 defined( $batch = $stream_cb->( { size => $batch_size } )->{items} ) )
32 {
33 56 ▶ if ($WITH_PM)
Branch: 1 branch
BranchTrueFalseTotal
if ($WITH_PM) 56 0 56
34 {
35 56 my $pid = $pm->start;
36  
37 56 ▶ if ($pid)
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) 40 16 56
38 {
39 40 next ITEMS;
40 }
41 }
42 16 $batch_cb->($batch);
43 16 ▶ if ($WITH_PM)
Branch: 1 branch
BranchTrueFalseTotal
if ($WITH_PM) 16 0 16
44 {
45 16 $pm->finish; # Terminates the child process
46 }
47 }
48 4 ▶ if ($WITH_PM)
Branch: 1 branch
BranchTrueFalseTotal
if ($WITH_PM) 4 0 4
49 {
50 4 $pm->wait_all_children;
51 }
52 4 return;
53 }
54  
55 22 1;
56  
57 __END__
↑ Summary Build »