|
NAMEPath::Extended::FileSYNOPSISuse Path::Extended::File; my $file = Path::Extended::File->new('path/to/file'); # you can get information of the file print $file->basename; # file print $file->absolute; # /absolute/path/to/file # you can get an object for the parent directory my $parent_dir = $file->parent; # Path::Extended::File object works like an IO handle $file->openr; my $first_line = $file->getline; print <$file>; close $file; # it also can do some extra file related tasks $file->copy_to('/other/path/to/file'); $file->unlink if $file->exists; $file->slurp(chomp => 1, callback => sub { my $line = shift; print $line, "\n" unless substr($line, 0, 1) eq '#'; }); file('/path/to/other_file')->save(\@lines, { mkdir => 1 }); # it has a logger, too $file->log( fatal => "Couldn't open $file: $!" ); DESCRIPTIONThis class implements file-specific methods. Most of them are simple wrappers of the equivalents from various File::* or IO::* classes. See also Path::Class::Entity for common methods like "copy" and "move".METHODSnewtakes a path or parts of a path of a file, and creates a Path::Extended::File object. If the path specified is a relative one, it will be converted to the absolute one internally. Note that this doesn't open a file even when you pass an extra file mode (which will be considered as a part of the file name).basenamereturns a base name of the file via "File::Basename::basename".openopens the file with a specified mode, and returns the $self object to chain methods, or undef if there's anything wrong (the handle opened is stored internally). You can use characters like "r" and "w", or symbols like "<" and ">". If you want to specify IO layers, use the latter format (e.g. "<:raw"). If the file is already open, it closes at first and opens again.openr, openwThese are shortcuts for ->open("r") and ->open("w") respectively.sysopentakes the third (and the fourth if necessary) arguments (i.e. mode and permission) of the native "sysopen", and opens the file, and returns the $self object, or undef if there's anything wrong. The handle opened is stored internally.binmodemay take an argument (to specify I/O layers), and arranges for the stored file handle to handle binary data properly. No effect if the file is not open.closecloses the stored file handle and removes it from the object. No effect if the file is not open.print, printf, say, getline, getlines, read, sysread, write, syswrite, autoflush, flush, printflush, getc, ungetc, truncate, blocking, eof, fileno, error, sync, fcntl, ioctlare simple wrappers of the equivalents of IO::Handle. No effect if the file is not open.lock_ex, lock_shlocks the stored file handle with "flock". No effect if the file is not open.seek, sysseek, tellare simple wrappers of the equirvalent built-in functions. Note that Path::Extended doesn't export constants like "SEEK_SET", "SEEK_CUR", "SEEK_END".mtimereturns a mtime of the file/directory. If you pass an argument, you can change the mtime of the file/directory.sizereturns a size of the file/directory.removeunlink the file.slurpmay take a hash (or a hash referernce) option, then opens the file, does various things for each line with callbacks if necessary, and returns an array of the lines (list context), or the concatenated string (scalar context).Options are:
grepmy @found = $file->grep('string or regex', ...); savetakes a string or an array reference of lines, and an optional hash (or a hash reference), then opens the file, does various things for each line (or the entire string) with callbacks if necessary, and saves the content to the file, and returns the $self object or undef if there's anything wrong.Options are:
touchchanges file access and modification times, or creates a blank file when it doesn't exist.AUTHORKenichi Ishigaki, <ishigaki@cpan.org>COPYRIGHT AND LICENSECopyright (C) 2008 by Kenichi Ishigaki.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |