This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In IPC::Open3::_open(), refactor the DO_SPAWN code to loop over @handles.
authorNicholas Clark <nick@ccl4.org>
Tue, 7 Jun 2011 11:00:33 +0000 (13:00 +0200)
committerNicholas Clark <nick@ccl4.org>
Sat, 11 Jun 2011 06:48:16 +0000 (08:48 +0200)
ext/IPC-Open3/lib/IPC/Open3.pm

index 60051ba..ed89f95 100644 (file)
@@ -320,27 +320,17 @@ sub _open3 {
        # handled in spawn_with_handles.
 
        my @close;
-       if ($handles[0]{dup}) {
-         $handles[0]{open_as} = $handles[0]{parent} =~ /\A[0-9]+\z/ ? $handles[0]{parent} : \*{$handles[0]{parent}};
-         push @close, $handles[0]{open_as};
-       } else {
-         push @close, \*{$handles[0]{parent}}, $handles[0]{open_as};
-       }
-       if ($handles[1]{dup}) {
-         $handles[1]{open_as} = $handles[1]{parent} =~ /\A[0-9]+\z/ ? $handles[1]{parent} : \*{$handles[1]{parent}};
-         push @close, $handles[1]{open_as};
-       } else {
-         push @close, \*{$handles[1]{parent}}, $handles[1]{open_as};
-       }
-       if (!$handles[2]{dup_of_out}) {
-           if ($handles[2]{dup}) {
-             $handles[2]{open_as} = $handles[2]{parent} =~ /\A[0-9]+\z/ ? $handles[2]{parent} : \*{$handles[2]{parent}};
-             push @close, $handles[2]{open_as};
+
+       foreach (@handles) {
+           if ($_->{dup_of_out}) {
+               $_->{open_as} = $handles[1]{open_as};
+           } elsif ($_->{dup}) {
+               $_->{open_as} = $_->{parent} =~ /\A[0-9]+\z/
+                   ? $_->{parent} : \*{$_->{parent}};
+               push @close, $_->{open_as};
            } else {
-             push @close, \*{$handles[2]{parent}}, $handles[2]{open_as};
+               push @close, \*{$_->{parent}}, $_->{open_as};
            }
-       } else {
-         $handles[2]{open_as} = $handles[1]{open_as};
        }
        require IO::Pipe;
        $kidpid = eval {