| 1 | package IPC::ForkPipe; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use 5.008008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 4 | require Exporter; | |||||||||
| 8 | |||||||||||
| 9 | 4 | our @ISA = qw(Exporter); | |||||||||
| 10 | 4 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||
| 11 | pipe_to_fork pipe_from_fork | ||||||||||
| 12 | ) ] ); | ||||||||||
| 13 | |||||||||||
| 14 | 4 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 15 | |||||||||||
| 16 | 4 | our @EXPORT = qw( | |||||||||
| 17 | pipe_to_fork pipe_from_fork | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 4 | our $VERSION = '0.01'; | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | # Code ganked from http://perldoc.perl.org/perlfork.html | ||||||||||
| 24 | |||||||||||
| 25 | # simulate open(FOO, "|-") | ||||||||||
| 26 | sub pipe_to_fork ($) { | ||||||||||
| 27 | 2 | ▶ | my $parent = shift; | ||||||||
|
Subroutine
pipe_to_fork: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||
| 28 | 2 | ▶ | pipe my $child, $parent or die; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 2 | my $pid = fork(); | |||||||||
| 30 | 2 | ▶ | return unless defined $pid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 2 | ▶ | if ($pid) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | close $child; | |||||||||
| 33 | } | ||||||||||
| 34 | else { | ||||||||||
| 35 | 1 | close $parent; | |||||||||
| 36 | 1 | ▶ | open(STDIN, "<&=" . fileno($child)) or die; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | } | ||||||||||
| 38 | 2 | return $pid; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # simulate open(FOO, "-|") | ||||||||||
| 42 | sub pipe_from_fork ($) { | ||||||||||
| 43 | 3 | ▶ | my $parent = shift; | ||||||||
|
Subroutine
pipe_from_fork: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||
| 44 | 3 | ▶ | pipe $parent, my $child or die; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 3 | my $pid = fork(); | |||||||||
| 46 | 3 | ▶ | return unless defined $pid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 3 | ▶ | if ($pid) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 2 | close $child; | |||||||||
| 49 | } | ||||||||||
| 50 | else { | ||||||||||
| 51 | 1 | close $parent; | |||||||||
| 52 | 1 | ▶ | open(STDOUT, ">&=" . fileno($child)) or die; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | } | ||||||||||
| 54 | 3 | return $pid; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 4 | 1; | |||||||||
| 58 | __END__ | ||||||||||