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.111 by root, Sat May 10 01:02:25 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.
561 561
562=item @AnyEvent::on_detect 562=item @AnyEvent::post_detect
563 563
564If there are any code references in this array (you can C<push> to it 564If 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 565before or after loading AnyEvent), then they will called directly after
566the event loop has been chosen. 566the event loop has been chosen.
567 567
568You should check C<$AnyEvent::MODEL> before adding to this array, though: 568You 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, 569if it contains a true value then the event loop has already been detected,
570and the array will be ignored. 570and the array will be ignored.
571 571
572Best use C<AnyEvent::on_detect { BLOCK }> instead. 572Best use C<AnyEvent::post_detect { BLOCK }> instead.
573 573
574=back 574=back
575 575
576=head1 WHAT TO DO IN A MODULE 576=head1 WHAT TO DO IN A MODULE
577 577
719 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza 719 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza
720); 720);
721 721
722our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); 722our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY);
723 723
724our @on_detect; 724our @post_detect;
725 725
726sub on_detect(&) { 726sub post_detect(&) {
727 my ($cb) = @_; 727 my ($cb) = @_;
728 728
729 if ($MODEL) { 729 if ($MODEL) {
730 $cb->(); 730 $cb->();
731 731
732 1 732 1
733 } else { 733 } else {
734 push @on_detect, $cb; 734 push @post_detect, $cb;
735 735
736 defined wantarray 736 defined wantarray
737 ? bless \$cb, "AnyEvent::Util::Guard" 737 ? bless \$cb, "AnyEvent::Util::Guard"
738 : () 738 : ()
739 } 739 }
740} 740}
741 741
742sub AnyEvent::Util::Guard::DESTROY { 742sub AnyEvent::Util::Guard::DESTROY {
743 @on_detect = grep $_ != ${$_[0]}, @on_detect; 743 @post_detect = grep $_ != ${$_[0]}, @post_detect;
744} 744}
745 745
746sub detect() { 746sub detect() {
747 unless ($MODEL) { 747 unless ($MODEL) {
748 no strict 'refs'; 748 no strict 'refs';
790 } 790 }
791 791
792 unshift @ISA, $MODEL; 792 unshift @ISA, $MODEL;
793 push @{"$MODEL\::ISA"}, "AnyEvent::Base"; 793 push @{"$MODEL\::ISA"}, "AnyEvent::Base";
794 794
795 (shift @on_detect)->() while @on_detect; 795 (shift @post_detect)->() while @post_detect;
796 } 796 }
797 797
798 $MODEL 798 $MODEL
799} 799}
800 800

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines