1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | AnyEvent - provide framework for multiple event loops |
3 | AnyEvent - provide framework for multiple event loops |
4 | |
4 | |
5 | EV, Event, Coro::EV, Coro::Event, Glib, Tk, Perl, Event::Lib - various supported event loops |
5 | EV, Event, Coro::EV, Coro::Event, Glib, Tk, Perl, Event::Lib, Qt - various supported event loops |
6 | |
6 | |
7 | =head1 SYNOPSIS |
7 | =head1 SYNOPSIS |
8 | |
8 | |
9 | use AnyEvent; |
9 | use AnyEvent; |
10 | |
10 | |
… | |
… | |
145 | events. C<poll> must be a string that is either C<r> or C<w>, which |
145 | events. C<poll> must be a string that is either C<r> or C<w>, which |
146 | creates a watcher waiting for "r"eadable or "w"ritable events, |
146 | creates a watcher waiting for "r"eadable or "w"ritable events, |
147 | respectively. C<cb> is the callback to invoke each time the file handle |
147 | respectively. C<cb> is the callback to invoke each time the file handle |
148 | becomes ready. |
148 | becomes ready. |
149 | |
149 | |
150 | File handles will be kept alive, so as long as the watcher exists, the |
150 | As long as the I/O watcher exists it will keep the file descriptor or a |
151 | file handle exists, too. |
151 | copy of it alive/open. |
152 | |
152 | |
153 | It is not allowed to close a file handle as long as any watcher is active |
153 | It is not allowed to close a file handle as long as any watcher is active |
154 | on the underlying file descriptor. |
154 | on the underlying file descriptor. |
155 | |
155 | |
156 | Some event loops issue spurious readyness notifications, so you should |
156 | Some event loops issue spurious readyness notifications, so you should |
… | |
… | |
353 | |
353 | |
354 | The known classes so far are: |
354 | The known classes so far are: |
355 | |
355 | |
356 | AnyEvent::Impl::CoroEV based on Coro::EV, best choice. |
356 | AnyEvent::Impl::CoroEV based on Coro::EV, best choice. |
357 | AnyEvent::Impl::CoroEvent based on Coro::Event, second best choice. |
357 | AnyEvent::Impl::CoroEvent based on Coro::Event, second best choice. |
358 | AnyEvent::Impl::EV based on EV (an interface to libev, also best choice). |
358 | AnyEvent::Impl::EV based on EV (an interface to libev, best choice). |
359 | AnyEvent::Impl::Event based on Event, also second best choice :) |
359 | AnyEvent::Impl::Event based on Event, second best choice. |
360 | AnyEvent::Impl::Glib based on Glib, third-best choice. |
360 | AnyEvent::Impl::Glib based on Glib, third-best choice. |
361 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
361 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
362 | AnyEvent::Impl::Perl pure-perl implementation, inefficient but portable. |
362 | AnyEvent::Impl::Perl pure-perl implementation, inefficient but portable. |
|
|
363 | AnyEvent::Impl::Qt based on Qt, cannot be autoprobed (see its docs). |
363 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
364 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
364 | |
365 | |
365 | =item AnyEvent::detect |
366 | =item AnyEvent::detect |
366 | |
367 | |
367 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
368 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
… | |
… | |
437 | [EV:: => AnyEvent::Impl::EV::], |
438 | [EV:: => AnyEvent::Impl::EV::], |
438 | [Event:: => AnyEvent::Impl::Event::], |
439 | [Event:: => AnyEvent::Impl::Event::], |
439 | [Glib:: => AnyEvent::Impl::Glib::], |
440 | [Glib:: => AnyEvent::Impl::Glib::], |
440 | [Tk:: => AnyEvent::Impl::Tk::], |
441 | [Tk:: => AnyEvent::Impl::Tk::], |
441 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
442 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
442 | [Event::Lib:: => AnyEvent::Impl::EventLib::], |
|
|
443 | ); |
443 | ); |
|
|
444 | my @models_detect = ( |
|
|
445 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
|
|
446 | [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy |
|
|
447 | ); |
444 | |
448 | |
445 | our %method = map +($_ => 1), qw(io timer condvar broadcast wait signal one_event DESTROY); |
449 | our %method = map +($_ => 1), qw(io timer signal child condvar broadcast wait one_event DESTROY); |
446 | |
450 | |
447 | sub detect() { |
451 | sub detect() { |
448 | unless ($MODEL) { |
452 | unless ($MODEL) { |
449 | no strict 'refs'; |
453 | no strict 'refs'; |
450 | |
454 | |
… | |
… | |
456 | } |
460 | } |
457 | } |
461 | } |
458 | |
462 | |
459 | # check for already loaded models |
463 | # check for already loaded models |
460 | unless ($MODEL) { |
464 | unless ($MODEL) { |
461 | for (@REGISTRY, @models) { |
465 | for (@REGISTRY, @models, @models_detect) { |
462 | my ($package, $model) = @$_; |
466 | my ($package, $model) = @$_; |
463 | if (${"$package\::VERSION"} > 0) { |
467 | if (${"$package\::VERSION"} > 0) { |
464 | if (eval "require $model") { |
468 | if (eval "require $model") { |
465 | $MODEL = $model; |
469 | $MODEL = $model; |
466 | warn "AnyEvent: autodetected model '$model', using it.\n" if $verbose > 1; |
470 | warn "AnyEvent: autodetected model '$model', using it.\n" if $verbose > 1; |
… | |
… | |
858 | |
862 | |
859 | =head1 SEE ALSO |
863 | =head1 SEE ALSO |
860 | |
864 | |
861 | Event modules: L<Coro::EV>, L<EV>, L<EV::Glib>, L<Glib::EV>, |
865 | Event modules: L<Coro::EV>, L<EV>, L<EV::Glib>, L<Glib::EV>, |
862 | L<Coro::Event>, L<Event>, L<Glib::Event>, L<Glib>, L<Coro>, L<Tk>, |
866 | L<Coro::Event>, L<Event>, L<Glib::Event>, L<Glib>, L<Coro>, L<Tk>, |
863 | L<Event::Lib>. |
867 | L<Event::Lib>, L<Qt>. |
864 | |
868 | |
865 | Implementations: L<AnyEvent::Impl::CoroEV>, L<AnyEvent::Impl::EV>, |
869 | Implementations: L<AnyEvent::Impl::CoroEV>, L<AnyEvent::Impl::EV>, |
866 | L<AnyEvent::Impl::CoroEvent>, L<AnyEvent::Impl::Event>, L<AnyEvent::Impl::Glib>, |
870 | L<AnyEvent::Impl::CoroEvent>, L<AnyEvent::Impl::Event>, L<AnyEvent::Impl::Glib>, |
867 | L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, L<AnyEvent::Impl::EventLib>. |
871 | L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, L<AnyEvent::Impl::EventLib>, |
|
|
872 | L<AnyEvent::Impl::Qt>. |
868 | |
873 | |
869 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>. |
874 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>. |
870 | |
875 | |
871 | =head1 AUTHOR |
876 | =head1 AUTHOR |
872 | |
877 | |