File Coverage

blib/lib/Proc/ForkSafe.pm
Criterion Covered Total %
statement 6 16 37.5
branch 0 4 0.0
condition n/a
subroutine 2 4 50.0
pod 0 2 0.0
total 8 26 30.7


line stmt bran cond sub pod time code
1             package Proc::ForkSafe;
2 1     1   69392 use strict;
  1         3  
  1         31  
3 1     1   5 use warnings;
  1         3  
  1         219  
4              
5             our $VERSION = '0.001';
6              
7             sub wrap {
8 0     0 0   my ($class, $new, $destroy) = @_;
9 0           my $obj = $new->();
10 0           bless { pid => $$, obj => $obj, new => $new, destroy => $destroy }, $class;
11             }
12              
13             sub call {
14 0     0 0   my ($self, $method, @argv) = @_;
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__