AnyEvent
view release on metacpan or search on metacpan
lib/AnyEvent/IO/Perl.pm view on Meta::CPAN
=head1 NAME
AnyEvent::IO::Perl - pure perl backend for AnyEvent::IO
=head1 SYNOPSIS
use AnyEvent::IO;
=head1 DESCRIPTION
This is the pure-perl backend of L<AnyEvent::IO> - it is always available,
but does not actually implement any I/O operation asynchronously -
everything is synchronous.
For simple programs that can wait for I/O, this is likely the most
efficient implementation.
=cut
package AnyEvent::IO::Perl;
use AnyEvent (); BEGIN { AnyEvent::common_sense }
our $VERSION = $AnyEvent::VERSION;
package AnyEvent::IO;
our $MODEL = "AnyEvent::IO::Perl";
sub aio_load($$) {
my ($path, $cb, $fh, $data) = @_;
$cb->(
(open $fh, "<:raw:perlio", $path
and stat $fh
and (-s _) == sysread $fh, $data, -s _)
? $data : ()
);
}
sub aio_open($$$$) {
sysopen my $fh, $_[0], $_[1], $_[2]
or return $_[3]();
$_[3]($fh)
}
sub aio_close($$) {
$_[1](close $_[0]);
}
sub aio_seek($$$$) {
my $data;
$_[3](sysseek $_[0], $_[1], $_[2] or ());
}
sub aio_read($$$) {
my $data;
$_[2]( (defined sysread $_[0], $data, $_[1]) ? $data : () );
}
sub aio_write($$$) {
my $res = syswrite $_[0], $_[1];
$_[2](defined $res ? $res : ());
}
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 ());
}
( run in 2.579 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )