File::Fu::File(3pm) | User Contributed Perl Documentation | File::Fu::File(3pm) |
File::Fu::File - a filename object
use File::Fu; my $file = File::Fu->file("path/to/file"); $file %= '.extension'; $file->e and warn "$file exists"; $file->l and warn "$file is a link to ", $file->readlink;
my $file = File::Fu::File->new($path); my $file = File::Fu::File->new(@path);
my $file = File::Fu::File->new_direct( dir => $dir_obj, file => $name );
Return the corresponding dir class for this file object. Default: File::Fu::Dir.
my $dc = $class->dir_class;
Always false for a file.
Always true for a file.
Returns a new object representing only the file part of the name.
my $obj = $file->basename;
my $string = $file->stringify;
Append a string only to the filename part.
$file->append('.gz'); $file %= '.gz';
(Yeah... I tried to use .=, but overloading hates me.)
$file->map(sub {...}); $file &= sub {...};
Get an absolute name (without checking the filesystem.)
my $abs = $file->absolute;
Get an absolute name (resolved on the filesytem.)
my $abs = $file->absolutely;
Open the file with $mode ('<', 'r', '>', 'w', etc) -- see IO::File.
my $fh = $file->open($mode, $permissions);
Throws an error if anything goes wrong or if the resulting filehandle happens to be a directory.
Interface to the sysopen() builtin. The value of $mode is a text string joined by '|' characters which must be valid O_* constants from Fcntl.
my $fh = $file->sysopen($mode, $perms);
Opens a read pipe. The file is appended to @command.
my $fh = $file->piped_open(@command);
Example: useless use of cat.
my $fh = $file->piped_open('cat');
This interface is deprecated (maybe) because it is limited to commands which take the $file as the last argument. See run() for the way of the future.
Treat $file as a program and execute a pipe open.
my $fh = $file->run(@args);
If called in void context, runs "system()" with autodie semantics and multi-arg form (suppresses shell interpolation.)
$file->run(@args);
No special treatment is made for whether $file is relative or not (the underlying "system()"/"exec()" will search your path.) Use File::Fu->which() to get an absolute path beforehand.
File::Fu->which('ls')->run('-l');
Update the timestamp of a file (or create it.)
$file->touch;
my $file = $file->mkfifo($mode);
my $link = $file->link($name);
my $link = $file->symlink($linkname);
Note that symlinks are relative to where they live.
my $dir = File::Fu->dir("foo"); my $file = $dir+'file'; # $file->symlink($dir+'link'); is a broken link my $link = $file->basename->symlink($dir+'link');
See "relative_symlink" in File::Fu::Base.
$file->unlink;
A forced unlink (chmod the file if it is not writable.)
$file->remove;
my $to = $file->readlink;
Read the entire file into memory (or swap!)
my @lines = $file->read; my $file = $file->read;
If File::Slurp is available, options to read_file will be passed along. See "read_file" in File::Slurp.
Write the file's contents. Returns the $file object for chaining.
$file = $file->write($content);
If File::Slurp is available, $content may be either a scalar, scalar ref, or array ref.
$file->write($content, %args);
Copies $file to $dest (which can be a file or directory) and returns the name of the new file as an object.
my $new = $file->copy($dest);
Note that if $dest is already a File object, that existing object will be returned.
my $new = $file->move($dest);
Eric Wilhelm @ <ewilhelm at cpan dot org>
http://scratchcomputing.com/
If you found this module on CPAN, please report any bugs or feature requests through the web interface at <http://rt.cpan.org>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
If you pulled this development version from my /svn/, please contact me directly.
Copyright (C) 2008 Eric L. Wilhelm, All Rights Reserved.
Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2022-12-07 | perl v5.36.0 |