This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Open3.pm:spawn_with_handles remove alot of duplicate operators
authorDaniel Dragan <bulk88@hotmail.com>
Sun, 13 Jul 2014 12:41:15 +0000 (08:41 -0400)
committerJames E Keenan <jkeenan@cpan.org>
Tue, 22 Jul 2014 01:15:57 +0000 (21:15 -0400)
dont call fileno twice, don't deref key "open_as" 3 extra times.

ext/IPC-Open3/lib/IPC/Open3.pm

index 99f120b..7911831 100644 (file)
@@ -362,7 +362,7 @@ sub open3 {
 sub spawn_with_handles {
     my $fds = shift;           # Fields: handle, mode, open_as
     my $close_in_child = shift;
-    my ($fd, $pid, @saved_fh, $saved, %saved, @errs);
+    my ($fd, $fileno, $open_as, $pid, @saved_fh, $saved, %saved, @errs);
 
     foreach $fd (@$fds) {
        $fd->{tmp_copy} = IO::Handle->new_from_fd($fd->{handle}, $fd->{mode});
@@ -373,9 +373,9 @@ sub spawn_with_handles {
            unless eval { $fd->{handle}->isa('IO::Handle') } ;
        # If some of handles to redirect-to coincide with handles to
        # redirect, we need to use saved variants:
-       $fd->{handle}->fdopen(defined fileno $fd->{open_as}
-                             ? $saved{fileno $fd->{open_as}} || $fd->{open_as}
-                             : $fd->{open_as},
+       $fd->{handle}->fdopen(defined($fileno = fileno($open_as = $fd->{open_as}))
+                             ? $saved{$fileno} || $open_as
+                             : $open_as,
                              $fd->{mode});
     }
     unless ($^O eq 'MSWin32') {