--- AnyEvent/lib/AnyEvent.pm 2008/05/01 13:45:22 1.106 +++ AnyEvent/lib/AnyEvent.pm 2008/05/10 00:45:18 1.109 @@ -2,7 +2,7 @@ AnyEvent - provide framework for multiple event loops -EV, Event, Coro::EV, Coro::Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops +EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops =head1 SYNOPSIS @@ -80,7 +80,7 @@ During the first call of any watcher-creation method, the module tries to detect the currently loaded event loop by probing whether one of the -following modules is already loaded: L, L, L, +following modules is already loaded: L, L, L, L, L, L, L, L. The first one found is used. If none are found, the module tries to load these modules (excluding Tk, Event::Lib, Qt and POE as the pure perl @@ -482,9 +482,13 @@ Another reason I to C<< ->wait >> in a module is that you cannot sensibly have two C<< ->wait >>'s in parallel, as that would require multiple interpreters or coroutines/threads, none of which C -can supply (the coroutine-aware backends L and -L explicitly support concurrent C<< ->wait >>'s -from different coroutines, however). +can supply. + +The L module, however, I and I supply coroutines and, in +fact, L replaces AnyEvent's condvars by coroutine-safe +versions and also integrates coroutines into AnyEvent, making blocking +C<< ->wait >> calls perfectly safe as long as they are done from another +coroutine (one that doesn't run the event loop). You can ensure that C<< -wait >> never blocks by setting a callback and only calling C<< ->wait >> from within that callback (or at a later @@ -521,8 +525,6 @@ The known classes so far are: - AnyEvent::Impl::CoroEV based on Coro::EV, best choice. - AnyEvent::Impl::CoroEvent based on Coro::Event, second best choice. AnyEvent::Impl::EV based on EV (an interface to libev, best choice). AnyEvent::Impl::Event based on Event, second best choice. AnyEvent::Impl::Perl pure-perl implementation, fast and portable. @@ -549,6 +551,23 @@ have created an AnyEvent watcher anyway, that is, as late as possible at runtime. +=item AnyEvent::on_detect { BLOCK } + +Arranges for the code block to be executed as soon as the event model is +autodetected (or immediately if this has already happened). + +=item @AnyEvent::on_detect + +If there are any code references in this array (you can C to it +before or after loading AnyEvent), then they will called directly after +the event loop has been chosen. + +You should check C<$AnyEvent::MODEL> before adding to this array, though: +if it contains a true value then the event loop has already been detected, +and the array will be ignored. + +Best use C instead. + =back =head1 WHAT TO DO IN A MODULE @@ -646,7 +665,7 @@ =item L -Has special support for AnyEvent. +Has special support for AnyEvent via L. =item L @@ -673,7 +692,7 @@ use Carp; -our $VERSION = '3.3'; +our $VERSION = '3.4'; our $MODEL; our $AUTOLOAD; @@ -684,8 +703,6 @@ our @REGISTRY; my @models = ( - [Coro::EV:: => AnyEvent::Impl::CoroEV::], - [Coro::Event:: => AnyEvent::Impl::CoroEvent::], [EV:: => AnyEvent::Impl::EV::], [Event:: => AnyEvent::Impl::Event::], [Tk:: => AnyEvent::Impl::Tk::], @@ -701,6 +718,16 @@ our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); +our @on_detect; + +sub on_detect(&) { + if ($MODEL) { + $_[0]->(); + } else { + push @on_detect, $_[0]; + } +} + sub detect() { unless ($MODEL) { no strict 'refs'; @@ -743,12 +770,14 @@ } $MODEL - or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: EV (or Coro+EV), Event (or Coro+Event) or Glib."; + or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: EV, Event or Glib."; } } unshift @ISA, $MODEL; push @{"$MODEL\::ISA"}, "AnyEvent::Base"; + + (shift @on_detect)->() while @on_detect; } $MODEL @@ -1392,17 +1421,22 @@ use AnyEvent; +Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can +be used to probe what backend is used and gain other information (which is +probably even less useful to an attacker than PERL_ANYEVENT_MODEL). + =head1 SEE ALSO -Event modules: L, L, L, L, -L, L, L, L, L, L, -L, L, L. - -Implementations: L, L, -L, L, L, -L, L, L, -L, L. +Event modules: L, L, L, L, L, +L, L, L, L, L. + +Implementations: L, L, +L, L, L, +L, L, +L. + +Coroutine support: L, L, L, L, Nontrivial usage examples: L, L.