File Coverage

blib/lib/Parallel/parallel_map.pm
Criterion Covered Total %
statement 19 19 100.0
branch 4 4 100.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             package Parallel::parallel_map;
2            
3 97     97   6929680 use 5.008;
  97         388  
4             our $VERSION = '0.03';
5            
6 97     97   970 use strict;
  97         194  
  97         3783  
7 97     97   776 use warnings;
  97         194  
  97         2522  
8 97     97   59752 use Parallel::DataPipe;
  97         2855583  
  97         19012  
9            
10             require Exporter;
11            
12             our @ISA = qw(Exporter);
13            
14             our @EXPORT = qw(parallel_map);
15            
16             our $INIT_DATA_PROCESSOR; # has to be code ref
17            
18             sub parallel_map(&@) {
19 342     342 0 886016 my ($code,@input) = @_;
20 342         1011 my (@result,@output);
21 342 100       1401 if (wantarray) {
22 325     30356   4590 @output = (output=>sub {my ($r,$i) = @_;$result[$i] = $r;});
  30356         12795457  
  30356         103237  
23             }
24             Parallel::DataPipe::run {
25 342         5870 input => \@input,
26             process => $code,
27             init_data_processor => $INIT_DATA_PROCESSOR, # this behaviour is introduced at 0.03
28             @output,
29             };
30 246 100       77679 return wantarray?@result:();
31             }
32            
33             1;
34            
35             __END__