File Coverage

blib/lib/CPAN/ParseDistribution/Unix.pm
Criterion Covered Total %
statement 20 20 100.0
branch 4 4 100.0
condition 2 3 66.6
subroutine 5 5 100.0
pod n/a
total 31 32 96.8


line stmt bran cond sub pod time code
1             package CPAN::ParseDistribution::Unix;
2              
3 89     89   267 use strict;
  89         89  
  89         2047  
4 89     89   267 use warnings;
  89         178  
  89         16643  
5              
6             =head1 NAME
7              
8             CPAN::ParseDistribution::Unix
9              
10             =head1 DESCRIPTION
11              
12             Unix-specific functionality
13              
14             =cut
15              
16             sub _run {
17 4004     4004   10126 my(undef, $safe_compartment, $code) = @_;
18 4004         3999 my $result;
19 4004         38469 my $fork_manager = Parallel::ForkManager->new(1);
20             # to retrieve data returned from child
21 4004     3916   4988439 $fork_manager->run_on_finish(sub { $result = $_[-1]; });
  3916         31029908  
22              
23             # checking time instead of saying run_on_wait(..., 5) is because of
24             # differences between 5.8.x and 5.18 (god knows when the difference came in)
25 4004         38109 my($start_time, $timed_out, $pid) = (time(), 0);
26             $fork_manager->run_on_wait(sub {
27 223664 100   223664   2238167236 if(time() - $start_time >= 5) {
28 16140         30504 $timed_out = 1;
29 16140         141786 kill(15, $pid);
30             }
31 4004         27079 }, 0.01);
32              
33 4004   66     27829 $pid = $fork_manager->start() || do {
34             my $v = eval { $safe_compartment->reval($code) };
35             if($@) { $result = { error => $@ }; }
36             else { $result = { result => $v }; }
37             $fork_manager->finish(0, $result);
38             };
39 3916         4066163 $fork_manager->wait_all_children();
40 3916 100       42027 $result->{error} = 'Safe compartment timed out' if($timed_out);
41 3916         25856 return $result;
42             }
43              
44             1;