… | |
… | |
549 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
549 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
550 | if necessary. You should only call this function right before you would |
550 | if necessary. You should only call this function right before you would |
551 | have created an AnyEvent watcher anyway, that is, as late as possible at |
551 | have created an AnyEvent watcher anyway, that is, as late as possible at |
552 | runtime. |
552 | runtime. |
553 | |
553 | |
|
|
554 | =item AnyEvent::on_detect { BLOCK } |
|
|
555 | |
|
|
556 | Arranges for the code block to be executed as soon as the event model is |
|
|
557 | autodetected (or immediately if this has already happened). |
|
|
558 | |
554 | =item @AnyEvent::detect |
559 | =item @AnyEvent::on_detect |
555 | |
560 | |
556 | If there are any code references in this array (you can C<push> to it |
561 | If there are any code references in this array (you can C<push> to it |
557 | before or after loading AnyEvent), then they will called directly after |
562 | before or after loading AnyEvent), then they will called directly after |
558 | the event loop has been chosen. |
563 | the event loop has been chosen. |
559 | |
564 | |
560 | You should check C<$AnyEvent::MODEL> before adding to this array, though: |
565 | You should check C<$AnyEvent::MODEL> before adding to this array, though: |
561 | if it contains a true value then the event loop has already been detected, |
566 | if it contains a true value then the event loop has already been detected, |
562 | and the array will be ignored. |
567 | and the array will be ignored. |
|
|
568 | |
|
|
569 | Best use C<AnyEvent::on_detect { BLOCK }> instead. |
563 | |
570 | |
564 | =back |
571 | =back |
565 | |
572 | |
566 | =head1 WHAT TO DO IN A MODULE |
573 | =head1 WHAT TO DO IN A MODULE |
567 | |
574 | |
… | |
… | |
709 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
716 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
710 | ); |
717 | ); |
711 | |
718 | |
712 | our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); |
719 | our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); |
713 | |
720 | |
714 | our @detect; |
721 | our @on_detect; |
|
|
722 | |
|
|
723 | sub on_detect(&) { |
|
|
724 | if ($MODEL) { |
|
|
725 | $_[0]->(); |
|
|
726 | } else { |
|
|
727 | push @on_detect, $_[0]; |
|
|
728 | } |
|
|
729 | } |
715 | |
730 | |
716 | sub detect() { |
731 | sub detect() { |
717 | unless ($MODEL) { |
732 | unless ($MODEL) { |
718 | no strict 'refs'; |
733 | no strict 'refs'; |
719 | |
734 | |
… | |
… | |
760 | } |
775 | } |
761 | |
776 | |
762 | unshift @ISA, $MODEL; |
777 | unshift @ISA, $MODEL; |
763 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
778 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
764 | |
779 | |
765 | (shift @detect)->() while @detect; |
780 | (shift @on_detect)->() while @on_detect; |
766 | } |
781 | } |
767 | |
782 | |
768 | $MODEL |
783 | $MODEL |
769 | } |
784 | } |
770 | |
785 | |