ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.110 by root, Sat May 10 00:57:31 2008 UTC vs.
Revision 1.113 by root, Sat May 10 20:30:35 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines