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.109 by root, Sat May 10 00:45:18 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 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
560that automatically removes the callback again when it is destroyed. See
561L<Coro::BDB> for a case where this is useful.
562
559=item @AnyEvent::on_detect 563=item @AnyEvent::post_detect
560 564
561If 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
562before or after loading AnyEvent), then they will called directly after 566before or after loading AnyEvent), then they will called directly after
563the event loop has been chosen. 567the event loop has been chosen.
564 568
565You should check C<$AnyEvent::MODEL> before adding to this array, though: 569You should check C<$AnyEvent::MODEL> before adding to this array, though:
566if 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,
567and the array will be ignored. 571and the array will be ignored.
568 572
569Best use C<AnyEvent::on_detect { BLOCK }> instead. 573Best 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
630Provide read and write buffers and manages watchers for reads and writes. 634Provide read and write buffers and manages watchers for reads and writes.
631 635
632=item L<AnyEvent::Socket>
633
634Provides a means to do non-blocking connects, accepts etc.
635
636=item L<AnyEvent::HTTPD> 636=item L<AnyEvent::HTTPD>
637 637
638Provides a simple web application server framework. 638Provides 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
668Has special support for AnyEvent via L<Coro::AnyEvent>. 668Has special support for AnyEvent via L<Coro::AnyEvent>.
669 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
670=item L<IO::Lambda> 681=item L<IO::Lambda>
671 682
672The 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.
673
674=item L<IO::AIO>
675
676Truly asynchronous I/O, should be in the toolbox of every event
677programmer. Can be trivially made to use AnyEvent.
678
679=item L<BDB>
680
681Truly asynchronous Berkeley DB access. Can be trivially made to use
682AnyEvent.
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
719our %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);
720 721
721our @on_detect; 722our @post_detect;
722 723
723sub on_detect(&) { 724sub 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
740sub AnyEvent::Util::Guard::DESTROY {
741 @post_detect = grep $_ != ${$_[0]}, @post_detect;
729} 742}
730 743
731sub detect() { 744sub 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines