| 1 | package Pipeline::Segment::Async::Fork; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Data::UUID; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Pipeline::Segment::Async::Handler; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use base qw( Pipeline::Segment::Async::Handler ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our $VERSION = "3.12"; | |||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | sub canop { 1 } | ||||||||
|
Subroutine
canop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||
| 15 | 1 | my $self = shift; | |||||||||
| 16 | 1 | my $sub = shift; | |||||||||
| 17 | 1 | my @args = @_; | |||||||||
| 18 | 1 | $self->create_id; | |||||||||
| 19 | 1 | ▶ | if (!(my $pid = fork())) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | require Storable; | |||||||||
| 21 | 0 | require File::Spec; | |||||||||
| 22 | 0 | my $results = $sub->( @args ); | |||||||||
| 23 | 0 | Storable::nstore( | |||||||||
| 24 | $results, | ||||||||||
| 25 | File::Spec->catfile( | ||||||||||
| 26 | File::Spec->tmpdir(), | ||||||||||
| 27 | $self->id | ||||||||||
| 28 | ) | ||||||||||
| 29 | ); | ||||||||||
| 30 | 0 | kill 9, $$; | |||||||||
| 31 | } else { | ||||||||||
| 32 | 1 | $self->pid( $pid ); | |||||||||
| 33 | 1 | return; | |||||||||
| 34 | } | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 1 | ▶ | sub create_id { | ||||||||
|
Subroutine
create_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 38 | 1 | my $self = shift; | |||||||||
| 39 | 1 | my $ug = Data::UUID->new(); | |||||||||
| 40 | 1 | my $uuid = $ug->create; | |||||||||
| 41 | 1 | my $id = $ug->to_string( $uuid ); | |||||||||
| 42 | 1 | $self->id( $id ); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 3 | ▶ | sub id { | ||||||||
|
Subroutine
id: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 46 | 3 | my $self = shift; | |||||||||
| 47 | 3 | my $id = shift; | |||||||||
| 48 | 3 | ▶ | if (defined( $id )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 1 | $self->{ thread_id } = $id; | |||||||||
| 50 | 1 | return $self; | |||||||||
| 51 | } else { | ||||||||||
| 52 | 2 | return $self->{ thread_id }; | |||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 3 | ▶ | sub pid { | ||||||||
|
Subroutine
pid: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 57 | 3 | my $self = shift; | |||||||||
| 58 | 3 | my $pid = shift; | |||||||||
| 59 | 3 | ▶ | if (defined( $pid )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 1 | $self->{ pid } = $pid; | |||||||||
| 61 | 1 | return $self; | |||||||||
| 62 | } else { | ||||||||||
| 63 | 2 | return $self->{ pid }; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | sub reattach { | ||||||||
|
Subroutine
reattach: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 68 | 1 | my $self = shift; | |||||||||
| 69 | 1 | ▶ | if (waitpid($self->pid, 0) == $self->pid) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 1 | require Storable; | |||||||||
| 71 | 1 | require File::Spec; | |||||||||
| 72 | 1 | my $return = Storable::retrieve( | |||||||||
| 73 | File::Spec->catfile( | ||||||||||
| 74 | File::Spec->tmpdir(), | ||||||||||
| 75 | $self->id | ||||||||||
| 76 | ) | ||||||||||
| 77 | ); | ||||||||||
| 78 | 1 | $self->unlink(); | |||||||||
| 79 | 1 | return $return; | |||||||||
| 80 | } else { | ||||||||||
| 81 | 0 | die "cannot wait for pid ". $self->pid; | |||||||||
| 82 | } | ||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | sub discard { | ||||||||
|
Subroutine
discard: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 86 | 0 | my $self = shift; | |||||||||
| 87 | 0 | $self->{ DESTROY_SHOULD_UNLINK } = 1; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | ▶ | sub unlink { | ||||||||
|
Subroutine
unlink: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 91 | 1 | my $self = shift; | |||||||||
| 92 | 1 | unlink( | |||||||||
| 93 | File::Spec->catfile( | ||||||||||
| 94 | File::Spec->tmpdir(), | ||||||||||
| 95 | $self->id | ||||||||||
| 96 | ) | ||||||||||
| 97 | ); | ||||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 1 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.2
| |||||||||||
| 101 | 1 | my $self = shift; | |||||||||
| 102 | 1 | ▶ | $self->unlink if $self->{ DESTROY_SHOULD_UNLINK }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | |||||||||||
| 106 | 1 | 1; | |||||||||
| 107 | __END__ | ||||||||||