7 IO::File - supply object methods for filehandles
14 if ($fh->open "< file") {
19 $fh = new IO::File "> FOO";
25 $fh = new IO::File "file", "r";
28 undef $fh; # automatically closes the file
31 $fh = new IO::File "file", O_WRONLY|O_APPEND;
34 undef $fh; # automatically closes the file
40 $fh->setvbuf($buffer_var, _IOLBF, 1024);
46 C<IO::File::new> creates a C<IO::File>, which is a reference to a
47 newly created symbol (see the C<Symbol> package). If it receives any
48 parameters, they are passed to C<IO::File::open>; if the open fails,
49 the C<IO::File> object is destroyed. Otherwise, it is returned to
52 C<IO::File::open> accepts one parameter or two. With one parameter,
53 it is just a front end for the built-in C<open> function. With two
54 parameters, the first parameter is a filename that may include
55 whitespace or other special characters, and the second parameter is
56 the open mode in either Perl form (">", "+<", etc.) or POSIX form
62 L<perlop/"I/O Operators">,
68 Derived from FileHandle.pm by Graham Barr <bodg@tiuk.ti.com>
77 use vars qw($VERSION @EXPORT @EXPORT_OK $AUTOLOAD);
82 use IO::Handle qw(_open_mode_string);
88 @ISA = qw(IO::Handle IO::Seekable Exporter DynaLoader);
90 $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
92 @EXPORT = @IO::Seekable::EXPORT;
94 ################################################
95 ## If the Fcntl extension is available,
96 ## export its constants.
101 my $callpkg = caller;
102 Exporter::export $pkg, $callpkg;
105 Exporter::export 'Fcntl', $callpkg;
110 ################################################
115 @_ >= 1 && @_ <= 3 or croak 'usage: new IO::File [FILENAME [,MODE]]';
117 my $fh = $class->SUPER::new();
125 ################################################
130 @_ >= 2 && @_ <= 4 or croak 'usage: $fh->open(FILENAME [,MODE [,PERMS]])';
131 my ($fh, $file) = @_;
133 my ($mode, $perms) = @_[2, 3];
134 if ($mode =~ /^\d+$/) {
135 defined $perms or $perms = 0666;
136 return sysopen($fh, $file, $mode, $perms);
138 $file = "./" . $file unless $file =~ m#^/#;
139 $file = _open_mode_string($mode) . " $file\0";