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 66     66   660 use strict;
  66         198  
  66         12738  
4 66     66   660 use warnings;
  66         198  
  66         33462  
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 2494     2494   8377 my(undef, $safe_compartment, $code) = @_;
18 2494         5712 my $result;
19 2494         119246 my $fork_manager = Parallel::ForkManager->new(1);
20             # to retrieve data returned from child
21 2494     2429   4115722 $fork_manager->run_on_finish(sub { $result = $_[-1]; });
  2429         65903118  
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 2494         36769 my($start_time, $timed_out, $pid) = (time(), 0);
26             $fork_manager->run_on_wait(sub {
27 395721 100   395721   4294919254 if(time() - $start_time >= 5) {
28 43471         45167262 $timed_out = 1;
29 43471         17327307 kill(15, $pid);
30             }
31 2494         39890 }, 0.01);
32              
33 2494   66     32406 $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 2429         8923474 $fork_manager->wait_all_children();
40 2429 100       49063 $result->{error} = 'Safe compartment timed out' if($timed_out);
41 2429         42018 return $result;
42             }
43              
44             1;