… | |
… | |
966 | You should check C<$AnyEvent::MODEL> before adding to this array, though: |
966 | You should check C<$AnyEvent::MODEL> before adding to this array, though: |
967 | if it is defined then the event loop has already been detected, and the |
967 | if it is defined then the event loop has already been detected, and the |
968 | array will be ignored. |
968 | array will be ignored. |
969 | |
969 | |
970 | Best use C<AnyEvent::post_detect { BLOCK }> when your application allows |
970 | Best use C<AnyEvent::post_detect { BLOCK }> when your application allows |
971 | it,as it takes care of these details. |
971 | it, as it takes care of these details. |
972 | |
972 | |
973 | This variable is mainly useful for modules that can do something useful |
973 | This variable is mainly useful for modules that can do something useful |
974 | when AnyEvent is used and thus want to know when it is initialised, but do |
974 | when AnyEvent is used and thus want to know when it is initialised, but do |
975 | not need to even load it by default. This array provides the means to hook |
975 | not need to even load it by default. This array provides the means to hook |
976 | into AnyEvent passively, without loading it. |
976 | into AnyEvent passively, without loading it. |
|
|
977 | |
|
|
978 | Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used |
|
|
979 | together, you could put this into Coro (this is the actual code used by |
|
|
980 | Coro to accomplish this): |
|
|
981 | |
|
|
982 | if (defined $AnyEvent::MODEL) { |
|
|
983 | # AnyEvent already initialised, so load Coro::AnyEvent |
|
|
984 | require Coro::AnyEvent; |
|
|
985 | } else { |
|
|
986 | # AnyEvent not yet initialised, so make sure to load Coro::AnyEvent |
|
|
987 | # as soon as it is |
|
|
988 | push @AnyEvent::post_detect, sub { require Coro::AnyEvent }; |
|
|
989 | } |
977 | |
990 | |
978 | =back |
991 | =back |
979 | |
992 | |
980 | =head1 WHAT TO DO IN A MODULE |
993 | =head1 WHAT TO DO IN A MODULE |
981 | |
994 | |