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, Qt - various supported event loops |
5 | EV, Event, Coro::EV, Coro::Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops |
6 | |
6 | |
7 | =head1 SYNOPSIS |
7 | =head1 SYNOPSIS |
8 | |
8 | |
9 | use AnyEvent; |
9 | use AnyEvent; |
10 | |
10 | |
… | |
… | |
78 | |
78 | |
79 | The interface itself is vaguely similar, but not identical to the L<Event> |
79 | The interface itself is vaguely similar, but not identical to the L<Event> |
80 | module. |
80 | module. |
81 | |
81 | |
82 | During the first call of any watcher-creation method, the module tries |
82 | During the first call of any watcher-creation method, the module tries |
83 | to detect the currently loaded event loop by probing whether one of |
83 | to detect the currently loaded event loop by probing whether one of the |
84 | the following modules is already loaded: L<Coro::EV>, L<Coro::Event>, |
84 | following modules is already loaded: L<Coro::EV>, L<Coro::Event>, L<EV>, |
85 | L<EV>, L<Event>, L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>. The first one |
85 | L<Event>, L<Glib>, L<Tk>, L<AnyEvent::Impl::Perl>, L<Event::Lib>, L<Qt>, |
86 | found is used. If none are found, the module tries to load these modules |
86 | L<POE>. The first one found is used. If none are found, the module tries |
87 | (excluding Event::Lib and Qt) in the order given. The first one that can |
87 | to load these modules (excluding Event::Lib, Qt and POE as the pure perl |
|
|
88 | adaptor should always succeed) in the order given. The first one that can |
88 | be successfully loaded will be used. If, after this, still none could be |
89 | be successfully loaded will be used. If, after this, still none could be |
89 | found, AnyEvent will fall back to a pure-perl event loop, which is not |
90 | found, AnyEvent will fall back to a pure-perl event loop, which is not |
90 | very efficient, but should work everywhere. |
91 | very efficient, but should work everywhere. |
91 | |
92 | |
92 | Because AnyEvent first checks for modules that are already loaded, loading |
93 | Because AnyEvent first checks for modules that are already loaded, loading |
… | |
… | |
362 | AnyEvent::Impl::Glib based on Glib, third-best choice. |
363 | AnyEvent::Impl::Glib based on Glib, third-best choice. |
363 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
364 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
364 | AnyEvent::Impl::Perl pure-perl implementation, inefficient but portable. |
365 | AnyEvent::Impl::Perl pure-perl implementation, inefficient but portable. |
365 | AnyEvent::Impl::Qt based on Qt, cannot be autoprobed (see its docs). |
366 | AnyEvent::Impl::Qt based on Qt, cannot be autoprobed (see its docs). |
366 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
367 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
|
|
368 | AnyEvent::Impl::POE based on POE, not generic enough for full support. |
|
|
369 | |
|
|
370 | There is no support for WxWidgets, as WxWidgets has no support for |
|
|
371 | watching file handles. However, you can use WxWidgets through the |
|
|
372 | POE Adaptor, as POE has a Wx backend that simply polls 20 times per |
|
|
373 | second, which was considered to be too horrible to even consider for |
|
|
374 | AnyEvent. Likewise, other POE backends can be used by AnyEvent by using |
|
|
375 | it's adaptor. |
|
|
376 | |
|
|
377 | AnyEvent knows about L<Prima> and L<Wx> and will try to use L<POE> when |
|
|
378 | autodetecting them. |
367 | |
379 | |
368 | =item AnyEvent::detect |
380 | =item AnyEvent::detect |
369 | |
381 | |
370 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
382 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
371 | if necessary. You should only call this function right before you would |
383 | if necessary. You should only call this function right before you would |
… | |
… | |
422 | no warnings; |
434 | no warnings; |
423 | use strict; |
435 | use strict; |
424 | |
436 | |
425 | use Carp; |
437 | use Carp; |
426 | |
438 | |
427 | our $VERSION = '3.12'; |
439 | our $VERSION = '3.3'; |
428 | our $MODEL; |
440 | our $MODEL; |
429 | |
441 | |
430 | our $AUTOLOAD; |
442 | our $AUTOLOAD; |
431 | our @ISA; |
443 | our @ISA; |
432 | |
444 | |
… | |
… | |
439 | [Coro::Event:: => AnyEvent::Impl::CoroEvent::], |
451 | [Coro::Event:: => AnyEvent::Impl::CoroEvent::], |
440 | [EV:: => AnyEvent::Impl::EV::], |
452 | [EV:: => AnyEvent::Impl::EV::], |
441 | [Event:: => AnyEvent::Impl::Event::], |
453 | [Event:: => AnyEvent::Impl::Event::], |
442 | [Glib:: => AnyEvent::Impl::Glib::], |
454 | [Glib:: => AnyEvent::Impl::Glib::], |
443 | [Tk:: => AnyEvent::Impl::Tk::], |
455 | [Tk:: => AnyEvent::Impl::Tk::], |
|
|
456 | [Wx:: => AnyEvent::Impl::POE::], |
|
|
457 | [Prima:: => AnyEvent::Impl::POE::], |
444 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
458 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
445 | ); |
459 | # everything below here will not be autoprobed as the pureperl backend should work everywhere |
446 | my @models_detect = ( |
460 | [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy |
447 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
461 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
448 | [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy |
462 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
449 | ); |
463 | ); |
450 | |
464 | |
451 | our %method = map +($_ => 1), qw(io timer signal child condvar broadcast wait one_event DESTROY); |
465 | our %method = map +($_ => 1), qw(io timer signal child condvar broadcast wait one_event DESTROY); |
452 | |
466 | |
453 | sub detect() { |
467 | sub detect() { |
… | |
… | |
457 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) { |
471 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) { |
458 | my $model = "AnyEvent::Impl::$1"; |
472 | my $model = "AnyEvent::Impl::$1"; |
459 | if (eval "require $model") { |
473 | if (eval "require $model") { |
460 | $MODEL = $model; |
474 | $MODEL = $model; |
461 | warn "AnyEvent: loaded model '$model' (forced by \$PERL_ANYEVENT_MODEL), using it.\n" if $verbose > 1; |
475 | warn "AnyEvent: loaded model '$model' (forced by \$PERL_ANYEVENT_MODEL), using it.\n" if $verbose > 1; |
|
|
476 | } else { |
|
|
477 | warn "AnyEvent: unable to load model '$model' (from \$PERL_ANYEVENT_MODEL):\n$@" if $verbose; |
462 | } |
478 | } |
463 | } |
479 | } |
464 | |
480 | |
465 | # check for already loaded models |
481 | # check for already loaded models |
466 | unless ($MODEL) { |
482 | unless ($MODEL) { |
467 | for (@REGISTRY, @models, @models_detect) { |
483 | for (@REGISTRY, @models) { |
468 | my ($package, $model) = @$_; |
484 | my ($package, $model) = @$_; |
469 | if (${"$package\::VERSION"} > 0) { |
485 | if (${"$package\::VERSION"} > 0) { |
470 | if (eval "require $model") { |
486 | if (eval "require $model") { |
471 | $MODEL = $model; |
487 | $MODEL = $model; |
472 | warn "AnyEvent: autodetected model '$model', using it.\n" if $verbose > 1; |
488 | warn "AnyEvent: autodetected model '$model', using it.\n" if $verbose > 1; |
… | |
… | |
659 | |
675 | |
660 | =over 4 |
676 | =over 4 |
661 | |
677 | |
662 | =item C<PERL_ANYEVENT_VERBOSE> |
678 | =item C<PERL_ANYEVENT_VERBOSE> |
663 | |
679 | |
|
|
680 | By default, AnyEvent will be completely silent except in fatal |
|
|
681 | conditions. You can set this environment variable to make AnyEvent more |
|
|
682 | talkative. |
|
|
683 | |
|
|
684 | When set to C<1> or higher, causes AnyEvent to warn about unexpected |
|
|
685 | conditions, such as not being able to load the event model specified by |
|
|
686 | C<PERL_ANYEVENT_MODEL>. |
|
|
687 | |
664 | When set to C<2> or higher, cause AnyEvent to report to STDERR which event |
688 | When set to C<2> or higher, cause AnyEvent to report to STDERR which event |
665 | model it chooses. |
689 | model it chooses. |
666 | |
690 | |
667 | =item C<PERL_ANYEVENT_MODEL> |
691 | =item C<PERL_ANYEVENT_MODEL> |
668 | |
692 | |
… | |
… | |
864 | |
888 | |
865 | =head1 SEE ALSO |
889 | =head1 SEE ALSO |
866 | |
890 | |
867 | Event modules: L<Coro::EV>, L<EV>, L<EV::Glib>, L<Glib::EV>, |
891 | Event modules: L<Coro::EV>, L<EV>, L<EV::Glib>, L<Glib::EV>, |
868 | L<Coro::Event>, L<Event>, L<Glib::Event>, L<Glib>, L<Coro>, L<Tk>, |
892 | L<Coro::Event>, L<Event>, L<Glib::Event>, L<Glib>, L<Coro>, L<Tk>, |
869 | L<Event::Lib>, L<Qt>. |
893 | L<Event::Lib>, L<Qt>, L<POE>. |
870 | |
894 | |
871 | Implementations: L<AnyEvent::Impl::CoroEV>, L<AnyEvent::Impl::EV>, |
895 | Implementations: L<AnyEvent::Impl::CoroEV>, L<AnyEvent::Impl::EV>, |
872 | L<AnyEvent::Impl::CoroEvent>, L<AnyEvent::Impl::Event>, L<AnyEvent::Impl::Glib>, |
896 | L<AnyEvent::Impl::CoroEvent>, L<AnyEvent::Impl::Event>, L<AnyEvent::Impl::Glib>, |
873 | L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, L<AnyEvent::Impl::EventLib>, |
897 | L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, L<AnyEvent::Impl::EventLib>, |
874 | L<AnyEvent::Impl::Qt>. |
898 | L<AnyEvent::Impl::Qt>, L<AnyEvent::Impl::POE>. |
875 | |
899 | |
876 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>. |
900 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>. |
877 | |
901 | |
878 | =head1 AUTHOR |
902 | =head1 AUTHOR |
879 | |
903 | |