This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bring '*' prototype closer to how it behaves internally
[perl5.git] / lib / FileHandle.pm
index aa8282b..eec9b61 100644 (file)
@@ -44,15 +44,22 @@ import IO::Handle grep { !defined(&$_) } @EXPORT, @EXPORT_OK;
 #
 {
     no strict 'refs';
-    for my $f (qw(DESTROY new_from_fd fdopen close fileno getc ungetc gets eof
-                 setbuf setvbuf _open_mode_string)) {
-       *{$f} = \&{"IO::Handle::$f"} or die "$f missing";
-    }
-    for my $f (qw(seek tell fgetpos fsetpos fflush ferror clearerr)) {
-       *{$f} = \&{"IO::Seekable::$f"} or die "$f missing";
-    }
-    for my $f (qw(new new_tmpfile open)) {
-       *{$f} = \&{"IO::File::$f"} or die "$f missing";
+
+    my %import = (
+       'IO::Handle' =>
+           [qw(DESTROY new_from_fd fdopen close fileno getc ungetc gets
+               eof flush error clearerr setbuf setvbuf _open_mode_string)],
+       'IO::Seekable' =>
+           [qw(seek tell getpos setpos)],
+       'IO::File' =>
+           [qw(new new_tmpfile open)]
+    );
+    for my $pkg (keys %import) {
+       for my $func (@{$import{$pkg}}) {
+           my $c = *{"${pkg}::$func"}{CODE}
+               or die "${pkg}::$func missing";
+           *$func = $c;
+       }
     }
 }
 
@@ -62,7 +69,8 @@ import IO::Handle grep { !defined(&$_) } @EXPORT, @EXPORT_OK;
 sub import {
     my $pkg = shift;
     my $callpkg = caller;
-    Exporter::export $pkg, $callpkg, @_;
+    require Exporter;
+    Exporter::export($pkg, $callpkg, @_);
 
     #
     # If the Fcntl extension is available,
@@ -70,7 +78,7 @@ sub import {
     #
     eval {
        require Fcntl;
-       Exporter::export 'Fcntl', $callpkg;
+       Exporter::export('Fcntl', $callpkg);
     };
 }
 
@@ -86,6 +94,11 @@ sub pipe {
     ($r, $w);
 }
 
+# Rebless standard file handles
+bless *STDIN{IO},  "FileHandle" if ref *STDIN{IO}  eq "IO::Handle";
+bless *STDOUT{IO}, "FileHandle" if ref *STDOUT{IO} eq "IO::Handle";
+bless *STDERR{IO}, "FileHandle" if ref *STDERR{IO} eq "IO::Handle";
+
 1;
 
 __END__
@@ -99,7 +112,7 @@ FileHandle - supply object methods for filehandles
     use FileHandle;
 
     $fh = new FileHandle;
-    if ($fh->open "< file") {
+    if ($fh->open("< file")) {
         print <$fh>;
         $fh->close;
     }
@@ -123,7 +136,7 @@ FileHandle - supply object methods for filehandles
     }
 
     $pos = $fh->getpos;
-    $fh->setpos $pos;
+    $fh->setpos($pos);
 
     $fh->setvbuf($buffer_var, _IOLBF, 1024);
 
@@ -236,6 +249,10 @@ It will also croak() if accidentally called in a scalar context.
 
 =back
 
+There are many other functions available since FileHandle is descended
+from IO::File, IO::Seekable, and IO::Handle.  Please see those
+respective pages for documentation on more functions.
+
 =head1 SEE ALSO
 
 The B<IO> extension,