… | |
… | |
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 } |
554 | =item $guard = AnyEvent::post_detect { BLOCK } |
555 | |
555 | |
556 | Arranges for the code block to be executed as soon as the event model is |
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). |
557 | autodetected (or immediately if this has already happened). |
558 | |
558 | |
|
|
559 | If called in scalar or list context, then it creates and returns an object |
|
|
560 | that automatically removes the callback again when it is destroyed. See |
|
|
561 | L<Coro::BDB> for a case where this is useful. |
|
|
562 | |
559 | =item @AnyEvent::on_detect |
563 | =item @AnyEvent::post_detect |
560 | |
564 | |
561 | If there are any code references in this array (you can C<push> to it |
565 | If there are any code references in this array (you can C<push> to it |
562 | before or after loading AnyEvent), then they will called directly after |
566 | before or after loading AnyEvent), then they will called directly after |
563 | the event loop has been chosen. |
567 | the event loop has been chosen. |
564 | |
568 | |
565 | You should check C<$AnyEvent::MODEL> before adding to this array, though: |
569 | You should check C<$AnyEvent::MODEL> before adding to this array, though: |
566 | if it contains a true value then the event loop has already been detected, |
570 | if it contains a true value then the event loop has already been detected, |
567 | and the array will be ignored. |
571 | and the array will be ignored. |
568 | |
572 | |
569 | Best use C<AnyEvent::on_detect { BLOCK }> instead. |
573 | Best use C<AnyEvent::post_detect { BLOCK }> instead. |
570 | |
574 | |
571 | =back |
575 | =back |
572 | |
576 | |
573 | =head1 WHAT TO DO IN A MODULE |
577 | =head1 WHAT TO DO IN A MODULE |
574 | |
578 | |
… | |
… | |
627 | |
631 | |
628 | =item L<AnyEvent::Handle> |
632 | =item L<AnyEvent::Handle> |
629 | |
633 | |
630 | Provide read and write buffers and manages watchers for reads and writes. |
634 | Provide read and write buffers and manages watchers for reads and writes. |
631 | |
635 | |
632 | =item L<AnyEvent::Socket> |
|
|
633 | |
|
|
634 | Provides a means to do non-blocking connects, accepts etc. |
|
|
635 | |
|
|
636 | =item L<AnyEvent::HTTPD> |
636 | =item L<AnyEvent::HTTPD> |
637 | |
637 | |
638 | Provides a simple web application server framework. |
638 | Provides a simple web application server framework. |
639 | |
639 | |
640 | =item L<AnyEvent::DNS> |
640 | =item L<AnyEvent::DNS> |
… | |
… | |
665 | |
665 | |
666 | =item L<Coro> |
666 | =item L<Coro> |
667 | |
667 | |
668 | Has special support for AnyEvent via L<Coro::AnyEvent>. |
668 | Has special support for AnyEvent via L<Coro::AnyEvent>. |
669 | |
669 | |
|
|
670 | =item L<AnyEvent::AIO>, L<IO::AIO> |
|
|
671 | |
|
|
672 | Truly asynchronous I/O, should be in the toolbox of every event |
|
|
673 | programmer. AnyEvent::AIO transparently fuses IO::AIO and AnyEvent |
|
|
674 | together. |
|
|
675 | |
|
|
676 | =item L<AnyEvent::BDB>, L<BDB> |
|
|
677 | |
|
|
678 | Truly asynchronous Berkeley DB access. AnyEvent::AIO transparently fuses |
|
|
679 | IO::AIO and AnyEvent together. |
|
|
680 | |
670 | =item L<IO::Lambda> |
681 | =item L<IO::Lambda> |
671 | |
682 | |
672 | The lambda approach to I/O - don't ask, look there. Can use AnyEvent. |
683 | The lambda approach to I/O - don't ask, look there. Can use AnyEvent. |
673 | |
|
|
674 | =item L<IO::AIO> |
|
|
675 | |
|
|
676 | Truly asynchronous I/O, should be in the toolbox of every event |
|
|
677 | programmer. Can be trivially made to use AnyEvent. |
|
|
678 | |
|
|
679 | =item L<BDB> |
|
|
680 | |
|
|
681 | Truly asynchronous Berkeley DB access. Can be trivially made to use |
|
|
682 | AnyEvent. |
|
|
683 | |
684 | |
684 | =back |
685 | =back |
685 | |
686 | |
686 | =cut |
687 | =cut |
687 | |
688 | |
… | |
… | |
716 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
717 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
717 | ); |
718 | ); |
718 | |
719 | |
719 | our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); |
720 | our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); |
720 | |
721 | |
721 | our @on_detect; |
722 | our @post_detect; |
722 | |
723 | |
723 | sub on_detect(&) { |
724 | sub post_detect(&) { |
|
|
725 | my ($cb) = @_; |
|
|
726 | |
724 | if ($MODEL) { |
727 | if ($MODEL) { |
725 | $_[0]->(); |
728 | $cb->(); |
|
|
729 | |
|
|
730 | 1 |
726 | } else { |
731 | } else { |
727 | push @on_detect, $_[0]; |
732 | push @post_detect, $cb; |
|
|
733 | |
|
|
734 | defined wantarray |
|
|
735 | ? bless \$cb, "AnyEvent::Util::Guard" |
|
|
736 | : () |
728 | } |
737 | } |
|
|
738 | } |
|
|
739 | |
|
|
740 | sub AnyEvent::Util::Guard::DESTROY { |
|
|
741 | @post_detect = grep $_ != ${$_[0]}, @post_detect; |
729 | } |
742 | } |
730 | |
743 | |
731 | sub detect() { |
744 | sub detect() { |
732 | unless ($MODEL) { |
745 | unless ($MODEL) { |
733 | no strict 'refs'; |
746 | no strict 'refs'; |
… | |
… | |
775 | } |
788 | } |
776 | |
789 | |
777 | unshift @ISA, $MODEL; |
790 | unshift @ISA, $MODEL; |
778 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
791 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
779 | |
792 | |
780 | (shift @on_detect)->() while @on_detect; |
793 | (shift @post_detect)->() while @post_detect; |
781 | } |
794 | } |
782 | |
795 | |
783 | $MODEL |
796 | $MODEL |
784 | } |
797 | } |
785 | |
798 | |