PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|AnyEvent.pm =

page 7 of 18



The callback will be called when the condition becomes "true", i.e. when
C<send> or C<croak> are called, with the only argument being the condition
variable itself. Calling C<recv> inside the callback or at any later time
is guaranteed not to block.

=back

=head1 GLOBAL VARIABLES AND FUNCTIONS

=over 4

=item $AnyEvent::MODEL

Contains C<undef> until the first watcher is being created. Then it
contains the event model that is being used, which is the name of the
Perl class implementing the model. This class is usually one of the
C<AnyEvent::Impl:xxx> modules, but can be any other class in the case
AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>).

The known classes so far are:

   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.
   AnyEvent::Impl::Glib      based on Glib, third-best choice.
   AnyEvent::Impl::Tk        based on Tk, very bad choice.
   AnyEvent::Impl::Qt        based on Qt, cannot be autoprobed (see its docs).
   AnyEvent::Impl::EventLib  based on Event::Lib, leaks memory and worse.
   AnyEvent::Impl::POE       based on POE, not generic enough for full support.

There is no support for WxWidgets, as WxWidgets has no support for
watching file handles. However, you can use WxWidgets through the
POE Adaptor, as POE has a Wx backend that simply polls 20 times per
second, which was considered to be too horrible to even consider for
AnyEvent. Likewise, other POE backends can be used by AnyEvent by using
it's adaptor.

AnyEvent knows about L<Prima> and L<Wx> and will try to use L<POE> when
autodetecting them.

=item AnyEvent::detect

Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model
if necessary. You should only call this function right before you would
have created an AnyEvent watcher anyway, that is, as late as possible at
runtime.

=item $guard = AnyEvent::post_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).

If called in scalar or list context, then it creates and returns an object
that automatically removes the callback again when it is destroyed. See
L<Coro::BDB> for a case where this is useful.

=item @AnyEvent::post_detect

If there are any code references in this array (you can C<push> 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<AnyEvent::post_detect { BLOCK }> instead.

=back

=head1 WHAT TO DO IN A MODULE

As a module author, you should C<use AnyEvent> and call AnyEvent methods
freely, but you should not load a specific event module or rely on it.

Be careful when you create watchers in the module body - AnyEvent will
decide which event module to use as soon as the first method is called, so
by calling AnyEvent in your module body you force the user of your module
to load the event module first.

Never call C<< ->recv >> on a condition variable unless you I<know> that
the C<< ->send >> method has been called on it already. This is
because it will stall the whole program, and the whole point of using
events is to stay interactive.

It is fine, however, to call C<< ->recv >> when the user of your module
requests it (i.e. if you create a http request object ad have a method
called C<results> that returns the results, it should call C<< ->recv >>
freely, as the user of your module knows what she is doing. always).

=head1 WHAT TO DO IN THE MAIN PROGRAM

There will always be a single main program - the only place that should
dictate which event model to use.

If it doesn't care, it can just "use AnyEvent" and use it itself, or not
do anything special (it does not need to be event-based) and let AnyEvent
decide which implementation to chose if some module relies on it.

If the main program relies on a specific event model - for example, in
=7=

1|2|3|4|5|6| < PREV = PAGE 7 = NEXT > |8|9|10|11|12|13|14|15|16.18

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00669599 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)