… | |
… | |
914 | $guard = AnyEvent::post_detect { BLOCK } |
914 | $guard = AnyEvent::post_detect { BLOCK } |
915 | Arranges for the code block to be executed as soon as the event |
915 | Arranges for the code block to be executed as soon as the event |
916 | model is autodetected (or immediately if that has already happened). |
916 | model is autodetected (or immediately if that has already happened). |
917 | |
917 | |
918 | The block will be executed *after* the actual backend has been |
918 | The block will be executed *after* the actual backend has been |
919 | detected ($AnyEvent::MODEL is set), but *before* any watchers have |
919 | detected ($AnyEvent::MODEL is set), so it is possible to do some |
920 | been created, so it is possible to e.g. patch @AnyEvent::ISA or do |
920 | initialisation only when AnyEvent is actually initialised - see the |
921 | other initialisations - see the sources of AnyEvent::Strict or |
|
|
922 | AnyEvent::AIO to see how this is used. |
921 | sources of AnyEvent::AIO to see how this is used. |
923 | |
922 | |
924 | The most common usage is to create some global watchers, without |
923 | The most common usage is to create some global watchers, without |
925 | forcing event module detection too early, for example, AnyEvent::AIO |
924 | forcing event module detection too early. For example, AnyEvent::AIO |
926 | creates and installs the global IO::AIO watcher in a "post_detect" |
925 | creates and installs the global IO::AIO watcher in a "post_detect" |
927 | block to avoid autodetecting the event module at load time. |
926 | block to avoid autodetecting the event module at load time. |
928 | |
927 | |
929 | If called in scalar or list context, then it creates and returns an |
928 | If called in scalar or list context, then it creates and returns an |
930 | object that automatically removes the callback again when it is |
929 | object that automatically removes the callback again when it is |
… | |
… | |
946 | # able to just C<undef $WATCHER> if the watcher causes them grief. |
945 | # able to just C<undef $WATCHER> if the watcher causes them grief. |
947 | |
946 | |
948 | $WATCHER ||= $guard; |
947 | $WATCHER ||= $guard; |
949 | |
948 | |
950 | @AnyEvent::post_detect |
949 | @AnyEvent::post_detect |
951 | If there are any code references in this array (you can "push" to it |
950 | This is a lower level interface then "AnyEvent::post_detect" (the |
952 | before or after loading AnyEvent), then they will be called directly |
951 | function). This variable is mainly useful for modules that can do |
|
|
952 | something useful when AnyEvent is used and thus want to know when it |
|
|
953 | is initialised, but do not need to even load it by default. This |
|
|
954 | array provides the means to hook into AnyEvent passively, without |
|
|
955 | loading it. |
|
|
956 | |
|
|
957 | Here is how it works: If there are any code references in this array |
|
|
958 | (you can "push" to it before or after loading AnyEvent), then they |
953 | after the event loop has been chosen. |
959 | will be called directly after the event loop has been chosen. |
954 | |
960 | |
955 | You should check $AnyEvent::MODEL before adding to this array, |
961 | You should check $AnyEvent::MODEL before adding to this array, |
956 | though: if it is defined then the event loop has already been |
962 | though: if it is defined then the event loop has already been |
957 | detected, and the array will be ignored. |
963 | detected, and the array will be ignored. |
958 | |
964 | |
959 | Best use "AnyEvent::post_detect { BLOCK }" when your application |
965 | Best use "AnyEvent::post_detect { BLOCK }" when your application |
960 | allows it, as it takes care of these details. |
966 | allows it, as it takes care of these details. |
961 | |
|
|
962 | This variable is mainly useful for modules that can do something |
|
|
963 | useful when AnyEvent is used and thus want to know when it is |
|
|
964 | initialised, but do not need to even load it by default. This array |
|
|
965 | provides the means to hook into AnyEvent passively, without loading |
|
|
966 | it. |
|
|
967 | |
967 | |
968 | Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used |
968 | Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used |
969 | together, you could put this into Coro (this is the actual code used |
969 | together, you could put this into Coro (this is the actual code used |
970 | by Coro to accomplish this): |
970 | by Coro to accomplish this): |
971 | |
971 | |