This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Implement the encoding pragma for regex literals.
[perl5.git] / lib / FileHandle.pm
index b215147..6be2242 100644 (file)
@@ -1,10 +1,10 @@
 package FileHandle;
 
-require 5.003;
+use 5.006;
 use strict;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
+our($VERSION, @ISA, @EXPORT, @EXPORT_OK);
 
-$VERSION = "2.00";
+$VERSION = "2.01";
 
 require IO::File;
 @ISA = qw(IO::File);
@@ -39,12 +39,38 @@ require IO::File;
 import IO::Handle grep { !defined(&$_) } @EXPORT, @EXPORT_OK;
 
 #
+# Some people call "FileHandle::function", so all the functions
+# that were in the old FileHandle class must be imported, too.
+#
+{
+    no strict 'refs';
+
+    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;
+       }
+    }
+}
+
+#
 # Specialized importer for Fcntl magic.
 #
 sub import {
     my $pkg = shift;
     my $callpkg = caller;
-    Exporter::export $pkg, $callpkg, @_;
+    require Exporter;
+    Exporter::export($pkg, $callpkg, @_);
 
     #
     # If the Fcntl extension is available,
@@ -52,7 +78,7 @@ sub import {
     #
     eval {
        require Fcntl;
-       Exporter::export 'Fcntl', $callpkg;
+       Exporter::export('Fcntl', $callpkg);
     };
 }
 
@@ -68,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__
@@ -81,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;
     }
@@ -105,7 +136,7 @@ FileHandle - supply object methods for filehandles
     }
 
     $pos = $fh->getpos;
-    $fh->setpos $pos;
+    $fh->setpos($pos);
 
     $fh->setvbuf($buffer_var, _IOLBF, 1024);
 
@@ -166,7 +197,7 @@ result!
 See L<perlfunc> for complete descriptions of each of the following
 supported C<FileHandle> methods, which are just front ends for the
 corresponding built-in functions:
-  
+
     close
     fileno
     getc
@@ -194,7 +225,7 @@ supported C<FileHandle> methods:
 
 Furthermore, for doing normal I/O you might need these:
 
-=over 
+=over 4
 
 =item $fh->print
 
@@ -207,17 +238,21 @@ See L<perlfunc/printf>.
 =item $fh->getline
 
 This works like <$fh> described in L<perlop/"I/O Operators">
-except that it's more readable and can be safely called in an
-array context but still returns just one line.
+except that it's more readable and can be safely called in a
+list context but still returns just one line.
 
 =item $fh->getlines
 
-This works like <$fh> when called in an array context to
+This works like <$fh> when called in a list context to
 read all the remaining lines in a file, except that it's more readable.
 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,