AnyEvent

 view release on metacpan or  search on metacpan

lib/AnyEvent/IO.pm  view on Meta::CPAN

=cut

package AnyEvent::IO;

use AnyEvent (); BEGIN { AnyEvent::common_sense }

use base "Exporter";

our @AIO_REQ = qw(
   aio_load aio_open aio_close aio_seek aio_read aio_write aio_truncate
   aio_utime aio_chown aio_chmod aio_stat aio_lstat
   aio_link aio_symlink aio_readlink aio_rename aio_unlink
   aio_mkdir aio_rmdir aio_readdir
);
*EXPORT = \@AIO_REQ;
our @FLAGS = qw(O_RDONLY O_WRONLY O_RDWR O_CREAT O_EXCL O_TRUNC O_APPEND);
*EXPORT_OK = \@FLAGS;
our %EXPORT_TAGS = (flags => \@FLAGS, aio => \@AIO_REQ);

our $MODEL;

lib/AnyEvent/IO.pm  view on Meta::CPAN

Calls C<utime> on the path or perl file handle and passes a true value to
the callback on success.

The special case of both C<$atime> and C<$mtime> being C<undef> sets the
times to the current time, on systems that support this.

Example: try to touch F<file>.

   aio_utime "file", undef, undef, sub { };

=item aio_chown $fh_or_path, $uid, $gid, $cb->($success)

Calls C<chown> on the path or perl file handle and passes a true value to
the callback on success.

If C<$uid> or C<$gid> can be specified as C<undef>, in which case the
uid or gid of the file is not changed. This differs from Perl's C<chown>
built-in, which wants C<-1> for this.

Example: update the group of F<file> to 0 (root), but leave the owner alone.

   aio_chown "file", undef, 0, sub {
      @_
         or return AE::log error => "chown 'file': $!";
   };

=item aio_chmod $fh_or_path, $perms, $cb->($success)

Calls C<chmod> on the path or perl file handle and passes a true value to
the callback on success.

Example: change F<file> to be user/group/world-readable, but leave the other flags
alone.

lib/AnyEvent/IO/IOAIO.pm  view on Meta::CPAN

sub aio_truncate($$$) {
   my $cb = $_[2];
   IO::AIO::aio_truncate $_[0], $_[1],              sub { $cb->($_[0] ? () : 1) };
}

sub aio_utime($$$$) {
   my $cb = $_[3];
   IO::AIO::aio_utime $_[0], $_[1], $_[2],          sub { $cb->($_[0] ? () : 1) };
}

sub aio_chown($$$$) {
   my $cb = $_[3];
   IO::AIO::aio_chown $_[0], $_[1], $_[2],          sub { $cb->($_[0] ? () : 1) };
}

sub aio_chmod($$$) {
   my $cb = $_[2];
   IO::AIO::aio_chmod $_[0], $_[1],                 sub { $cb->($_[0] ? () : 1) };
}

sub aio_stat($$) {
   my $cb = $_[1];
   IO::AIO::aio_stat $_[0],                         sub { $cb->($_[0] ? () : 1) };

lib/AnyEvent/IO/Perl.pm  view on Meta::CPAN


sub aio_truncate($$$) {
   #TODO: raises an exception on !truncate|ftruncate systems, maybe eval + set errno?
   $_[2](truncate $_[0], $_[1] or ());
}

sub aio_utime($$$$) {
   $_[3](utime $_[1], $_[2], $_[0] or ());
}

sub aio_chown($$$$) {
   $_[3](chown defined $_[1] ? $_[1] : -1, defined $_[2] ? $_[2] : -1, $_[0] or ());
}

sub aio_chmod($$$) {
   $_[2](chmod $_[1], $_[0] or ());
}

sub aio_stat($$) {
   $_[1](stat  $_[0]);
}

t/io_common  view on Meta::CPAN

#! perl

$| = 1;

# not tested: symlink, readlink, link, utime, chown, chmod

BEGIN {
   print "1..37\n";
   print "ok 1 # MODEL=$AnyEvent::IO::MODEL\n";
}
use AnyEvent;
use AnyEvent::IO qw(:DEFAULT :flags);
BEGIN {
   print "ok 2 # MODEL=$AnyEvent::IO::MODEL\n";
}



( run in 2.349 seconds using v1.01-cache-2.11-cpan-71847e10f99 )