File::Fu::File - a filename object


NAME

File::Fu::File - a filename object

Back to Top


SYNOPSIS

  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;

Back to Top


Constructor

new

  my $file = File::Fu::File->new($path);
  my $file = File::Fu::File->new(@path);

new_direct

  my $file = File::Fu::File->new_direct(
    dir => $dir_obj,
    file => $name
  );

Back to Top


Class Constants

dir_class

Return the corresponding dir class for this file object.

  my $dc = $class->dir_class;

is_dir

Always false for a file.

is_file

Always true for a file.

Back to Top


Parts

basename

Returns a new object representing only the file part of the name.

  my $obj = $file->basename;

Back to Top


Methods

stringify

  my $string = $file->stringify;

append

Append a string only to the filename part.

  $file->append('.gz');
  $file %= '.gz';

(Yeah... I tried to use .=, but overloading hates me.)

map

  $file->map(sub {...});
  $file &= sub {...};

absolute

Get an absolute name (without checking the filesystem.)

  my $abs = $file->absolute;

absolutely

Get an absolute name (resolved on the filesytem.)

  my $abs = $file->absolutely;

Back to Top


Doing stuff

open

Open the file with $mode ('<', 'r', '>', 'w', etc) -- see the IO::File manpage.

  my $fh = $file->open($mode, $permissions);

Throws an error if anything goes wrong or if the resulting filehandle happens to be a directory.

piped_open

Opens a read pipe. The file is appended to @command.

  my $fh = $file->piped_open(@command);

touch

Update the timestamp of a file (or create it.)

  $file->touch;

link

  my $link = $file->link($name);

symlink

  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');

rename

Calls the builtin rename() on the $file and returns a new object with that name.

  $file = $file->rename($newname);

unlink

  $file->unlink;

readlink

  my $to = $file->readlink;

read

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 the File::Slurp manpage.

write

Write the file's contents.

  $file->write($content);

If File::Slurp is available, $content may be either a scalar, scalar ref, or array ref.

  $file->write($content, %args);

copy

  $file->copy($dest);

Back to Top


AUTHOR

Eric Wilhelm @ <ewilhelm at cpan dot org>

http://scratchcomputing.com/

Back to Top


BUGS

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.

Back to Top


COPYRIGHT

Copyright (C) 2008 Eric L. Wilhelm, All Rights Reserved.

Back to Top


NO WARRANTY

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.

Back to Top


LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Back to Top

 File::Fu::File - a filename object