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.108 by root, Sat May 10 00:22:02 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::post_detect { BLOCK }
555
556Arranges for the code block to be executed as soon as the event model is
557autodetected (or immediately if this has already happened).
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
554=item @AnyEvent::detect 563=item @AnyEvent::post_detect
555 564
556If 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
557before or after loading AnyEvent), then they will called directly after 566before or after loading AnyEvent), then they will called directly after
558the event loop has been chosen. 567the event loop has been chosen.
559 568
560You should check C<$AnyEvent::MODEL> before adding to this array, though: 569You should check C<$AnyEvent::MODEL> before adding to this array, though:
561if 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,
562and the array will be ignored. 571and the array will be ignored.
572
573Best use C<AnyEvent::post_detect { BLOCK }> instead.
563 574
564=back 575=back
565 576
566=head1 WHAT TO DO IN A MODULE 577=head1 WHAT TO DO IN A MODULE
567 578
620 631
621=item L<AnyEvent::Handle> 632=item L<AnyEvent::Handle>
622 633
623Provide read and write buffers and manages watchers for reads and writes. 634Provide read and write buffers and manages watchers for reads and writes.
624 635
625=item L<AnyEvent::Socket>
626
627Provides a means to do non-blocking connects, accepts etc.
628
629=item L<AnyEvent::HTTPD> 636=item L<AnyEvent::HTTPD>
630 637
631Provides a simple web application server framework. 638Provides a simple web application server framework.
632 639
633=item L<AnyEvent::DNS> 640=item L<AnyEvent::DNS>
658 665
659=item L<Coro> 666=item L<Coro>
660 667
661Has special support for AnyEvent via L<Coro::AnyEvent>. 668Has special support for AnyEvent via L<Coro::AnyEvent>.
662 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
663=item L<IO::Lambda> 681=item L<IO::Lambda>
664 682
665The 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.
666
667=item L<IO::AIO>
668
669Truly asynchronous I/O, should be in the toolbox of every event
670programmer. Can be trivially made to use AnyEvent.
671
672=item L<BDB>
673
674Truly asynchronous Berkeley DB access. Can be trivially made to use
675AnyEvent.
676 684
677=back 685=back
678 686
679=cut 687=cut
680 688
709 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza 717 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza
710); 718);
711 719
712our %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);
713 721
714our @detect; 722our @post_detect;
723
724sub post_detect(&) {
725 my ($cb) = @_;
726
727 if ($MODEL) {
728 $cb->();
729
730 1
731 } else {
732 push @post_detect, $cb;
733
734 defined wantarray
735 ? bless \$cb, "AnyEvent::Util::Guard"
736 : ()
737 }
738}
739
740sub AnyEvent::Util::Guard::DESTROY {
741 @post_detect = grep $_ != ${$_[0]}, @post_detect;
742}
715 743
716sub detect() { 744sub detect() {
717 unless ($MODEL) { 745 unless ($MODEL) {
718 no strict 'refs'; 746 no strict 'refs';
719 747
760 } 788 }
761 789
762 unshift @ISA, $MODEL; 790 unshift @ISA, $MODEL;
763 push @{"$MODEL\::ISA"}, "AnyEvent::Base"; 791 push @{"$MODEL\::ISA"}, "AnyEvent::Base";
764 792
765 (shift @detect)->() while @detect; 793 (shift @post_detect)->() while @post_detect;
766 } 794 }
767 795
768 $MODEL 796 $MODEL
769} 797}
770 798

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines