ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.55 by root, Wed Apr 23 11:25:42 2008 UTC vs.
Revision 1.57 by root, Thu Apr 24 03:19:28 2008 UTC

1=head1 NAME 1=head1 NAME
2 2
3AnyEvent - provide framework for multiple event loops 3AnyEvent - provide framework for multiple event loops
4 4
5EV, Event, Coro::EV, Coro::Event, Glib, Tk, Perl, Event::Lib - various supported event loops 5EV, 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
78 78
79The interface itself is vaguely similar, but not identical to the L<Event> 79The interface itself is vaguely similar, but not identical to the L<Event>
80module. 80module.
81 81
82During the first call of any watcher-creation method, the module tries 82During the first call of any watcher-creation method, the module tries
83to detect the currently loaded event loop by probing whether one of the 83to detect the currently loaded event loop by probing whether one of
84following modules is already loaded: L<Coro::EV>, L<Coro::Event>, L<EV>, 84the following modules is already loaded: L<Coro::EV>, L<Coro::Event>,
85L<Event>, L<Glib>, L<Tk>. The first one found is used. If none are found, 85L<EV>, L<Event>, L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>. The first one
86the module tries to load these modules in the stated order. The first one 86found is used. If none are found, the module tries to load these modules
87(excluding Event::Lib and Qt) in the order given. The first one that can
87that can be successfully loaded will be used. If, after this, still none 88be successfully loaded will be used. If, after this, still none could be
88could be found, AnyEvent will fall back to a pure-perl event loop, which 89found, AnyEvent will fall back to a pure-perl event loop, which is not
89is not very efficient, but should work everywhere. 90very efficient, but should work everywhere.
90 91
91Because AnyEvent first checks for modules that are already loaded, loading 92Because AnyEvent first checks for modules that are already loaded, loading
92an event model explicitly before first using AnyEvent will likely make 93an event model explicitly before first using AnyEvent will likely make
93that model the default. For example: 94that model the default. For example:
94 95
145events. C<poll> must be a string that is either C<r> or C<w>, which 146events. C<poll> must be a string that is either C<r> or C<w>, which
146creates a watcher waiting for "r"eadable or "w"ritable events, 147creates a watcher waiting for "r"eadable or "w"ritable events,
147respectively. C<cb> is the callback to invoke each time the file handle 148respectively. C<cb> is the callback to invoke each time the file handle
148becomes ready. 149becomes ready.
149 150
150File handles will be kept alive, so as long as the watcher exists, the 151As long as the I/O watcher exists it will keep the file descriptor or a
151file handle exists, too. 152copy of it alive/open.
152 153
153It is not allowed to close a file handle as long as any watcher is active 154It is not allowed to close a file handle as long as any watcher is active
154on the underlying file descriptor. 155on the underlying file descriptor.
155 156
156Some event loops issue spurious readyness notifications, so you should 157Some event loops issue spurious readyness notifications, so you should
353 354
354The known classes so far are: 355The known classes so far are:
355 356
356 AnyEvent::Impl::CoroEV based on Coro::EV, best choice. 357 AnyEvent::Impl::CoroEV based on Coro::EV, best choice.
357 AnyEvent::Impl::CoroEvent based on Coro::Event, second best choice. 358 AnyEvent::Impl::CoroEvent based on Coro::Event, second best choice.
358 AnyEvent::Impl::EV based on EV (an interface to libev, also best choice). 359 AnyEvent::Impl::EV based on EV (an interface to libev, best choice).
359 AnyEvent::Impl::Event based on Event, also second best choice :) 360 AnyEvent::Impl::Event based on Event, second best choice.
360 AnyEvent::Impl::Glib based on Glib, third-best choice. 361 AnyEvent::Impl::Glib based on Glib, third-best choice.
361 AnyEvent::Impl::Tk based on Tk, very bad choice. 362 AnyEvent::Impl::Tk based on Tk, very bad choice.
362 AnyEvent::Impl::Perl pure-perl implementation, inefficient but portable. 363 AnyEvent::Impl::Perl pure-perl implementation, inefficient but portable.
364 AnyEvent::Impl::Qt based on Qt, cannot be autoprobed (see its docs).
363 AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. 365 AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse.
364 366
365=item AnyEvent::detect 367=item AnyEvent::detect
366 368
367Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model 369Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model
437 [EV:: => AnyEvent::Impl::EV::], 439 [EV:: => AnyEvent::Impl::EV::],
438 [Event:: => AnyEvent::Impl::Event::], 440 [Event:: => AnyEvent::Impl::Event::],
439 [Glib:: => AnyEvent::Impl::Glib::], 441 [Glib:: => AnyEvent::Impl::Glib::],
440 [Tk:: => AnyEvent::Impl::Tk::], 442 [Tk:: => AnyEvent::Impl::Tk::],
441 [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], 443 [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::],
442 [Event::Lib:: => AnyEvent::Impl::EventLib::],
443); 444);
445my @models_detect = (
446 [Qt:: => AnyEvent::Impl::Qt::], # requires special main program
447 [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy
448);
444 449
445our %method = map +($_ => 1), qw(io timer condvar broadcast wait signal one_event DESTROY); 450our %method = map +($_ => 1), qw(io timer signal child condvar broadcast wait one_event DESTROY);
446 451
447sub detect() { 452sub detect() {
448 unless ($MODEL) { 453 unless ($MODEL) {
449 no strict 'refs'; 454 no strict 'refs';
450 455
456 } 461 }
457 } 462 }
458 463
459 # check for already loaded models 464 # check for already loaded models
460 unless ($MODEL) { 465 unless ($MODEL) {
461 for (@REGISTRY, @models) { 466 for (@REGISTRY, @models, @models_detect) {
462 my ($package, $model) = @$_; 467 my ($package, $model) = @$_;
463 if (${"$package\::VERSION"} > 0) { 468 if (${"$package\::VERSION"} > 0) {
464 if (eval "require $model") { 469 if (eval "require $model") {
465 $MODEL = $model; 470 $MODEL = $model;
466 warn "AnyEvent: autodetected model '$model', using it.\n" if $verbose > 1; 471 warn "AnyEvent: autodetected model '$model', using it.\n" if $verbose > 1;
858 863
859=head1 SEE ALSO 864=head1 SEE ALSO
860 865
861Event modules: L<Coro::EV>, L<EV>, L<EV::Glib>, L<Glib::EV>, 866Event modules: L<Coro::EV>, L<EV>, L<EV::Glib>, L<Glib::EV>,
862L<Coro::Event>, L<Event>, L<Glib::Event>, L<Glib>, L<Coro>, L<Tk>, 867L<Coro::Event>, L<Event>, L<Glib::Event>, L<Glib>, L<Coro>, L<Tk>,
863L<Event::Lib>. 868L<Event::Lib>, L<Qt>.
864 869
865Implementations: L<AnyEvent::Impl::CoroEV>, L<AnyEvent::Impl::EV>, 870Implementations: L<AnyEvent::Impl::CoroEV>, L<AnyEvent::Impl::EV>,
866L<AnyEvent::Impl::CoroEvent>, L<AnyEvent::Impl::Event>, L<AnyEvent::Impl::Glib>, 871L<AnyEvent::Impl::CoroEvent>, L<AnyEvent::Impl::Event>, L<AnyEvent::Impl::Glib>,
867L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, L<AnyEvent::Impl::EventLib>. 872L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, L<AnyEvent::Impl::EventLib>,
873L<AnyEvent::Impl::Qt>.
868 874
869Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>. 875Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>.
870 876
871=head1 AUTHOR 877=head1 AUTHOR
872 878

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines