Ancient

 view release on metacpan or  search on metacpan

lib/file.pm  view on Meta::CPAN

Returns true if path is a directory.

=head2 is_readable

    if (file::is_readable($path)) { ... }

Returns true if path is readable.

=head2 is_writable

    if (file::is_writable($path)) { ... }

Returns true if path is writable.

=head2 is_executable

    if (file::is_executable($path)) { ... }

Returns true if path is executable.

=head2 is_link

    if (file::is_link($path)) { ... }

Returns true if path is a symbolic link.

=head2 atime

    my $epoch = file::atime($path);

Returns access time as epoch seconds, or -1 on error.

=head2 ctime

    my $epoch = file::ctime($path);

Returns change time as epoch seconds, or -1 on error.

=head2 mode

    my $mode = file::mode($path);

Returns file permission mode (e.g., 0644), or -1 on error.

=head2 unlink

    my $ok = file::unlink($path);

Delete a file. Returns true on success.

=head2 copy

    my $ok = file::copy($src, $dst);

Copy a file. Returns true on success. Preserves file permissions.

=head2 move

    my $ok = file::move($src, $dst);

Move/rename a file. Returns true on success. Works across filesystems.

=head2 touch

    my $ok = file::touch($path);

Create file or update modification time. Returns true on success.

=head2 chmod

    my $ok = file::chmod($path, $mode);

Change file permissions. Returns true on success.

    file::chmod('/path/to/file', 0755);

=head2 mkdir

    my $ok = file::mkdir($path);
    my $ok = file::mkdir($path, $mode);

Create a directory. Default mode is 0755. Returns true on success.

=head2 rmdir

    my $ok = file::rmdir($path);

Remove an empty directory. Returns true on success.

=head2 readdir

    my $entries = file::readdir($path);

Returns arrayref of directory entries (excluding . and ..).

=head2 atomic_spew

    my $ok = file::atomic_spew($path, $data);

Write data atomically using a temp file + rename. Returns true on success.
This is safe against partial writes and power failures.

=head2 basename

    my $name = file::basename($path);

Returns the filename portion of a path.

    file::basename('/path/to/file.txt')  # returns 'file.txt'

=head2 dirname

    my $dir = file::dirname($path);

Returns the directory portion of a path.

    file::dirname('/path/to/file.txt')  # returns '/path/to'

=head2 extname

    my $ext = file::extname($path);

Returns the file extension including the dot.

    file::extname('/path/to/file.txt')  # returns '.txt'

=head2 join

    my $path = file::join(@parts);

Join path components with the appropriate separator.

    file::join('path', 'to', 'file')  # returns 'path/to/file'

=head2 head

    my $lines = file::head($path);
    my $lines = file::head($path, $n);

Returns arrayref of first N lines (default 10).

=head2 tail

    my $lines = file::tail($path);
    my $lines = file::tail($path, $n);

Returns arrayref of last N lines (default 10).

=head1 CUSTOM OP IMPORT

For maximum performance, you can import function-style accessors that
use custom ops instead of method calls:

    use file qw(import);

    my $content = file_slurp($path);     # custom op, fastest
    file_spew($path, $data);
    my $exists = file_exists($path);
    my $size = file_size($path);
    my $is_file = file_is_file($path);



( run in 2.396 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )