… | |
… | |
809 | |
809 | |
810 | =back |
810 | =back |
811 | |
811 | |
812 | =head1 GLOBAL VARIABLES AND FUNCTIONS |
812 | =head1 GLOBAL VARIABLES AND FUNCTIONS |
813 | |
813 | |
|
|
814 | These are not normally required to use AnyEvent, but can be useful to |
|
|
815 | write AnyEvent extension modules. |
|
|
816 | |
814 | =over 4 |
817 | =over 4 |
815 | |
818 | |
816 | =item $AnyEvent::MODEL |
819 | =item $AnyEvent::MODEL |
817 | |
820 | |
818 | Contains C<undef> until the first watcher is being created. Then it |
821 | Contains C<undef> until the first watcher is being created, before the |
|
|
822 | backend has been autodetected. |
|
|
823 | |
819 | contains the event model that is being used, which is the name of the |
824 | Afterwards it contains the event model that is being used, which is the |
820 | Perl class implementing the model. This class is usually one of the |
825 | name of the Perl class implementing the model. This class is usually one |
821 | C<AnyEvent::Impl:xxx> modules, but can be any other class in the case |
826 | of the C<AnyEvent::Impl:xxx> modules, but can be any other class in the |
822 | AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>). |
827 | case AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode> it |
|
|
828 | will be C<urxvt::anyevent>). |
823 | |
829 | |
824 | =item AnyEvent::detect |
830 | =item AnyEvent::detect |
825 | |
831 | |
826 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
832 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
827 | if necessary. You should only call this function right before you would |
833 | if necessary. You should only call this function right before you would |
828 | have created an AnyEvent watcher anyway, that is, as late as possible at |
834 | have created an AnyEvent watcher anyway, that is, as late as possible at |
829 | runtime. |
835 | runtime, and not e.g. while initialising of your module. |
|
|
836 | |
|
|
837 | If you need to do some initialisation before AnyEvent watchers are |
|
|
838 | created, use C<post_detect>. |
830 | |
839 | |
831 | =item $guard = AnyEvent::post_detect { BLOCK } |
840 | =item $guard = AnyEvent::post_detect { BLOCK } |
832 | |
841 | |
833 | Arranges for the code block to be executed as soon as the event model is |
842 | Arranges for the code block to be executed as soon as the event model is |
834 | autodetected (or immediately if this has already happened). |
843 | autodetected (or immediately if this has already happened). |
|
|
844 | |
|
|
845 | The block will be executed I<after> the actual backend has been detected |
|
|
846 | (C<$AnyEvent::MODEL> is set), but I<before> any watchers have been |
|
|
847 | created, so it is possible to e.g. patch C<@AnyEvent::ISA> or do |
|
|
848 | other initialisations - see the sources of L<AnyEvent::Strict> or |
|
|
849 | L<AnyEvent::AIO> to see how this is used. |
|
|
850 | |
|
|
851 | The most common usage is to create some global watchers, without forcing |
|
|
852 | event module detection too early, for example, L<AnyEvent::AIO> creates |
|
|
853 | and installs the global L<IO::AIO> watcher in a C<post_detect> block to |
|
|
854 | avoid autodetecting the event module at load time. |
835 | |
855 | |
836 | If called in scalar or list context, then it creates and returns an object |
856 | If called in scalar or list context, then it creates and returns an object |
837 | that automatically removes the callback again when it is destroyed. See |
857 | that automatically removes the callback again when it is destroyed. See |
838 | L<Coro::BDB> for a case where this is useful. |
858 | L<Coro::BDB> for a case where this is useful. |
839 | |
859 | |
… | |
… | |
842 | If there are any code references in this array (you can C<push> to it |
862 | If there are any code references in this array (you can C<push> to it |
843 | before or after loading AnyEvent), then they will called directly after |
863 | before or after loading AnyEvent), then they will called directly after |
844 | the event loop has been chosen. |
864 | the event loop has been chosen. |
845 | |
865 | |
846 | You should check C<$AnyEvent::MODEL> before adding to this array, though: |
866 | You should check C<$AnyEvent::MODEL> before adding to this array, though: |
847 | if it contains a true value then the event loop has already been detected, |
867 | if it is defined then the event loop has already been detected, and the |
848 | and the array will be ignored. |
868 | array will be ignored. |
849 | |
869 | |
850 | Best use C<AnyEvent::post_detect { BLOCK }> instead. |
870 | Best use C<AnyEvent::post_detect { BLOCK }> when your application allows |
|
|
871 | it,as it takes care of these details. |
|
|
872 | |
|
|
873 | This variable is mainly useful for modules that can do something useful |
|
|
874 | when AnyEvent is used and thus want to know when it is initialised, but do |
|
|
875 | not need to even load it by default. This array provides the means to hook |
|
|
876 | into AnyEvent passively, without loading it. |
851 | |
877 | |
852 | =back |
878 | =back |
853 | |
879 | |
854 | =head1 WHAT TO DO IN A MODULE |
880 | =head1 WHAT TO DO IN A MODULE |
855 | |
881 | |