Integrate macperl patch #16868.
[p5sagit/p5-mst-13.2.git] / ext / IO / lib / IO / Pipe.pm
index 499856a..0b5aac4 100644 (file)
@@ -1,20 +1,20 @@
 # IO::Pipe.pm
 #
-# Copyright (c) 1996 Graham Barr <Graham.Barr@tiuk.ti.com>. All rights
-# reserved. This program is free software; you can redistribute it and/or
+# Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
+# This program is free software; you can redistribute it and/or
 # modify it under the same terms as Perl itself.
 
 package IO::Pipe;
 
-require 5.000;
+use 5.006_001;
 
 use IO::Handle;
 use strict;
-use vars qw($VERSION);
+our($VERSION);
 use Carp;
 use Symbol;
 
-$VERSION = "1.09";
+$VERSION = "1.122";
 
 sub new {
     my $type = shift;
@@ -65,6 +65,7 @@ sub _doit {
         }
         bless $io, "IO::Handle";
         $io->fdopen($fh, $mode);
+       $fh->close;
 
         if ($do_spawn) {
           $pid = eval { system 1, @_ }; # 1 == P_NOWAIT
@@ -87,15 +88,21 @@ sub _doit {
 }
 
 sub reader {
-    @_ >= 1 or croak 'usage: $pipe->reader()';
+    @_ >= 1 or croak 'usage: $pipe->reader( [SUB_COMMAND_ARGS] )';
     my $me = shift;
+
+    return undef
+       unless(ref($me) || ref($me = $me->new));
+
     my $fh  = ${*$me}[0];
     my $pid = $me->_doit(0, $fh, @_)
         if(@_);
 
     close ${*$me}[1];
     bless $me, ref($fh);
-    *{*$me} = *{*$fh};          # Alias self to handle
+    *$me = *$fh;          # Alias self to handle
+    $me->fdopen($fh->fileno,"r")
+       unless defined($me->fileno);
     bless $fh;                  # Really wan't un-bless here
     ${*$me}{'io_pipe_pid'} = $pid
         if defined $pid;
@@ -104,15 +111,21 @@ sub reader {
 }
 
 sub writer {
-    @_ >= 1 or croak 'usage: $pipe->writer()';
+    @_ >= 1 or croak 'usage: $pipe->writer( [SUB_COMMAND_ARGS] )';
     my $me = shift;
+
+    return undef
+       unless(ref($me) || ref($me = $me->new));
+
     my $fh  = ${*$me}[1];
     my $pid = $me->_doit(1, $fh, @_)
         if(@_);
 
     close ${*$me}[0];
     bless $me, ref($fh);
-    *{*$me} = *{*$fh};          # Alias self to handle
+    *$me = *$fh;          # Alias self to handle
+    $me->fdopen($fh->fileno,"w")
+       unless defined($me->fileno);
     bless $fh;                  # Really wan't un-bless here
     ${*$me}{'io_pipe_pid'} = $pid
         if defined $pid;
@@ -122,7 +135,7 @@ sub writer {
 
 package IO::Pipe::End;
 
-use vars qw(@ISA);
+our(@ISA);
 
 @ISA = qw(IO::Handle);
 
@@ -142,7 +155,7 @@ __END__
 
 =head1 NAME
 
-IO::pipe - supply object methods for pipes
+IO::Pipe - supply object methods for pipes
 
 =head1 SYNOPSIS
 
@@ -153,15 +166,15 @@ IO::pipe - supply object methods for pipes
        if($pid = fork()) { # Parent
            $pipe->reader();
 
-           while(<$pipe> {
-               ....
+           while(<$pipe>) {
+               ...
            }
 
        }
        elsif(defined $pid) { # Child
            $pipe->writer();
 
-           print $pipe ....
+           print $pipe ...
        }
 
        or
@@ -171,26 +184,26 @@ IO::pipe - supply object methods for pipes
        $pipe->reader(qw(ls -l));
 
        while(<$pipe>) {
-           ....
+           ...
        }
 
 =head1 DESCRIPTION
 
-C<IO::Pipe> provides an interface to createing pipes between
+C<IO::Pipe> provides an interface to creating pipes between
 processes.
 
-=head1 CONSTRCUTOR
+=head1 CONSTRUCTOR
 
 =over 4
 
 =item new ( [READER, WRITER] )
 
-Creates a C<IO::Pipe>, which is a reference to a
-newly created symbol (see the C<Symbol> package). C<IO::Pipe::new>
-optionally takes two arguments, which should be objects blessed into
-C<IO::Handle>, or a subclass thereof. These two objects will be used
-for the system call to C<pipe>. If no arguments are given then then
-method C<handles> is called on the new C<IO::Pipe> object.
+Creates an C<IO::Pipe>, which is a reference to a newly created symbol
+(see the C<Symbol> package). C<IO::Pipe::new> optionally takes two
+arguments, which should be objects blessed into C<IO::Handle>, or a
+subclass thereof. These two objects will be used for the system call
+to C<pipe>. If no arguments are given then method C<handles> is called
+on the new C<IO::Pipe> object.
 
 These two handles are held in the array part of the GLOB until either
 C<reader> or C<writer> is called.
@@ -227,12 +240,13 @@ L<IO::Handle>
 
 =head1 AUTHOR
 
-Graham Barr <bodg@tiuk.ti.com>
+Graham Barr. Currently maintained by the Perl Porters.  Please report all
+bugs to <perl5-porters@perl.org>.
 
 =head1 COPYRIGHT
 
-Copyright (c) 1996 Graham Barr. All rights reserved. This program is free
-software; you can redistribute it and/or modify it under the same terms
-as Perl itself.
+Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
+This program is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
 
 =cut