1=head1 NAME 2 3AnyEvent::Impl::EV - AnyEvent adaptor for EV 4 5=head1 SYNOPSIS 6 7 use AnyEvent; 8 use EV; 9 10 # this module gets loaded automatically as required 11 12=head1 DESCRIPTION 13 14This module provides transparent support for AnyEvent. You don't have to 15do anything to make EV work with AnyEvent except by loading EV before 16creating the first AnyEvent watcher. 17 18EV is the fastest event library for perl, and best supported by 19AnyEvent. Most functions from the L<AE> API are implemented as direct 20aliases to EV functions, so using EV via AE is as fast as using EV 21directly. 22 23=cut 24 25package AnyEvent::Impl::EV; 26 27use AnyEvent (); BEGIN { AnyEvent::common_sense } 28use EV 4.00; 29 30*AE::time = \&EV::time; 31*AE::now = \&EV::now; 32*AE::now_update = \&EV::now_update; 33*AE::timer = \&EV::timer; 34*AE::signal = \&EV::signal; 35*AE::idle = \&EV::idle; 36 37# cannot override directly, as EV doesn't allow arguments 38sub time { EV::time } 39sub now { EV::now } 40sub now_update { EV::now_update } 41 42*AE::io = defined &EV::_ae_io # 3.8+, but keep just in case it is dropped 43 ? \&EV::_ae_io 44 : sub($$$) { EV::io $_[0], $_[1] ? EV::WRITE : EV::READ, $_[2] }; 45 46sub timer { 47 my ($class, %arg) = @_; 48 49 EV::timer $arg{after}, $arg{interval}, $arg{cb} 50} 51 52sub io { 53 my ($class, %arg) = @_; 54 55 EV::io 56 $arg{fh}, 57 $arg{poll} eq "r" ? EV::READ : EV::WRITE, 58 $arg{cb} 59} 60 61sub signal { 62 my ($class, %arg) = @_; 63 64 EV::signal $arg{signal}, $arg{cb} 65} 66 67sub child { 68 my ($class, %arg) = @_; 69 70 my $cb = $arg{cb}; 71 72 EV::child $arg{pid}, 0, sub { 73 $cb->($_[0]->rpid, $_[0]->rstatus); 74 } 75} 76 77sub idle { 78 my ($class, %arg) = @_; 79 80 EV::idle $arg{cb} 81} 82 83sub _poll { 84 EV::run EV::RUN_ONCE; 85} 86 87sub AnyEvent::CondVar::Base::_wait { 88 EV::run EV::RUN_ONCE until exists $_[0]{_ae_sent}; 89} 90 91#sub loop { 92# EV::run; 93#} 94 95=head1 SEE ALSO 96 97L<AnyEvent>, L<EV>. 98 99=head1 AUTHOR 100 101 Marc Lehmann <schmorp@schmorp.de> 102 http://anyevent.schmorp.de 103 104=cut 105 1061 107 108