File Coverage

blib/lib/Parallel/Map/Segmented.pm
Criterion Covered Total %
statement 26 30 86.6
branch 4 6 66.6
condition 3 3 100.0
subroutine 7 8 87.5
pod 1 1 100.0
total 41 48 85.4


line stmt bran cond sub pod time code
1             package Parallel::Map::Segmented;
2             $Parallel::Map::Segmented::VERSION = '0.2.1';
3 5     5   291655 use strict;
  5         49  
  5         130  
4 5     5   22 use warnings;
  5         9  
  5         107  
5 5     5   107 use 5.014;
  5         15  
6              
7 5     5   1995 use parent 'Parallel::ForkManager::Segmented::Base';
  5         1267  
  5         22  
8              
9 5     5   5955 use Parallel::Map qw/ pmap_void /;
  5         440216  
  5         1102  
10              
11             sub run
12             {
13 5     5 1 49872 my ( $self, $args ) = @_;
14              
15 5         30 my $processed = $self->process_args($args);
16 5 100       162 return if not $processed;
17             my ( $WITH_PM, $batch_cb, $batch_size, $nproc, $stream_cb, ) =
18 4         9 @{$processed}{qw/ WITH_PM batch_cb batch_size nproc stream_cb /};
  4         16  
19              
20 4         20 my $batch = $stream_cb->( { size => 1 } )->{items};
21 4 50       50 return if not defined $batch;
22 4         14 $batch_cb->($batch);
23 4 50       5385 if ($WITH_PM)
24             {
25 0     0   0 pmap_void sub { $batch_cb->(shift); Future->done; }, generate => sub {
  0         0  
26 36   100 36   158000 return $stream_cb->( { size => $batch_size } )->{items} // ();
27             },
28 4         59 ;
29             }
30             else
31             {
32 0         0 while (
33             defined(
34             $batch = $stream_cb->( { size => $batch_size } )->{items}
35             )
36             )
37             {
38 0         0 $batch_cb->($batch);
39             }
40             }
41 4         29432 return;
42             }
43              
44             1;
45              
46             __END__