File Coverage

blib/lib/Proc/ForkSafe.pm
Criterion Covered Total %
statement 8 26 30.7
branch 0 4 0.0
condition n/a
subroutine 3 5 60.0
pod 0 2 0.0
total 11 37 29.7


line stmt bran cond sub pod time code
1             package Proc::ForkSafe v1.0.0;
2 1     1   102172 use v5.24;
  1         4  
3 1     1   5 use warnings;
  1         4  
  1         52  
4 1     1   3 use experimental qw(lexical_subs signatures);
  1         2  
  1         7  
5              
6             our $TRIAL = 0;
7              
8              
9 0     0 0   sub wrap ($class, $new, $destroy = undef) {
  0            
  0            
  0            
  0            
10 0           my $obj = $new->();
11 0           bless { pid => $$, obj => $obj, new => $new, destroy => $destroy }, $class;
12             }
13              
14 0     0 0   sub call ($self, $method, @argv) {
  0            
  0            
  0            
  0            
15 0 0         if ($self->{pid} != $$) {
16 0 0         $self->{destroy}->($self->{obj}) if $self->{destroy};
17 0           undef $self->{obj};
18 0           $self->{obj} = $self->{new}->();
19 0           $self->{pid} = $$;
20             }
21 0           $self->{obj}->$method(@argv);
22             }
23              
24             1;
25             __END__