AnyEvent
view release on metacpan or search on metacpan
lib/AnyEvent/IO.pm view on Meta::CPAN
=item aio_stat $fh_or_path, $cb->($success)
=item aio_lstat $path, $cb->($success)
Calls C<stat> or C<lstat> on the path or perl file handle and passes a
true value to the callback on success.
The stat data will be available by C<stat>'ing the C<_> file handle
(e.g. C<-x _>, C<stat _> and so on).
Example: see if we can find the number of subdirectories of F</etc>.
aio_stat "/etc", sub {
@_
or return AE::log error => "/etc: $!";
(stat _)[3] >= 2
or return AE::log warn => "/etc has low link count - non-POSIX filesystem?";
print "/etc has ", (stat _)[3] - 2, " subdirectories.\n";
};
=item aio_link $oldpath, $newpath, $cb->($success)
Calls C<link> on the paths and passes a true value to the callback on
success.
Example: link "F<file> to F<file.bak>, then rename F<file.new> over F<file>,
to atomically replace it.
aio_link "file", "file.bak", sub {
@_
or return AE::log error => "file: $!";
aio_rename "file.new", "file", sub {
@_
or return AE::log error => "file.new: $!";
print "file atomically replaced by file.new, backup file.bak\n";
};
};
=item aio_symlink $oldpath, $newpath, $cb->($success)
Calls C<symlink> on the paths and passes a true value to the callback on
success.
Example: create a symlink "F<slink> containing "random data".
aio_symlink "random data", "slink", sub {
@_
or return AE::log error => "slink: $!";
};
=item aio_readlink $path, $cb->($target)
Calls C<readlink> on the paths and passes the link target string to the
callback.
Example: read the symlink called Fyslink> and verify that it contains "random data".
aio_readlink "slink", sub {
my ($target) = @_
or return AE::log error => "slink: $!";
$target eq "random data"
or AE::log critical => "omg, the world will end!";
};
=item aio_rename $oldpath, $newpath, $cb->($success)
Calls C<rename> on the paths and passes a true value to the callback on
success.
See C<aio_link> for an example.
=item aio_unlink $path, $cb->($success)
Tries to unlink the object at C<$path> and passes a true value to the
callback on success.
Example: try to delete the file F<tmpfile.dat~>.
aio_unlink "tmpfile.dat~", sub { };
=item aio_mkdir $path, $perms, $cb->($success)
Calls C<mkdir> on the path with the given permissions C<$perms> (when in
doubt, C<0777> is a good value) and passes a true value to the callback on
success.
Example: try to create the directory F<subdir> and leave it to whoeveer
comes after us to check whether it worked.
aio_mkdir "subdir", 0777, sub { };
=item aio_rmdir $path, $cb->($success)
Tries to remove the directory at C<$path> and passes a true value to the
callback on success.
Example: try to remove the directory F<subdir> and don't give a damn if
that fails.
aio_rmdir "subdir", sub { };
=item aio_readdir $path, $cb->(\@names)
Reads all filenames from the directory specified by C<$path> and passes
them to the callback, as an array reference with the names (without a path
prefix). The F<.> and F<..> names will be filtered out first.
The ordering of the file names is undefined - backends that are capable
of it (e.g. L<IO::AIO>) will return the ordering that most likely is
fastest to C<stat> through, and furthermore put entries that likely are
directories first in the array.
If you need best performance in recursive directory traversal or when
looking at really big directories, you are advised to use L<IO::AIO>
directly, specifically the C<aio_readdirx> and C<aio_scandir> functions,
( run in 0.966 second using v1.01-cache-2.11-cpan-39bf76dae61 )