--- AnyEvent/lib/AnyEvent.pm 2008/05/25 04:44:04 1.134 +++ AnyEvent/lib/AnyEvent.pm 2008/05/26 06:04:38 1.139 @@ -314,7 +314,8 @@ After creation, the condition variable is "false" until it becomes "true" by calling the C method (or calling the condition variable as if it -were a callback). +were a callback, read about the caveats in the description for the C<< +->send >> method). Condition variables are similar to callbacks, except that you can optionally wait for them. They can also be called merge points - points @@ -396,8 +397,14 @@ Any arguments passed to the C call will be returned by all future C<< ->recv >> calls. -Condition variables are overloaded so one can call them directly (as a -code reference). Calling them directly is the same as calling C. +Condition variables are overloaded so one can call them directly +(as a code reference). Calling them directly is the same as calling +C. Note, however, that many C-based event loops do not handle +overloading, so as tempting as it may be, passing a condition variable +instead of a callback does not work. Both the pure perl and EV loops +support overloading, however, as well as all functions that use perl to +invoke a callback (as in L and L for +example). =item $cv->croak ($error) @@ -726,36 +733,59 @@ use Carp; -our $VERSION = '4.03'; +our $VERSION = '4.04'; our $MODEL; our $AUTOLOAD; our @ISA; -our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; - our @REGISTRY; -our %PROTOCOL; # (ipv4|ipv6) => (1|2) +our $WIN32; + +BEGIN { + my $win32 = ! ! ($^O =~ /mswin32/i); + eval "sub WIN32(){ $win32 }"; +} + +our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; + +our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred { my $idx; $PROTOCOL{$_} = ++$idx - for split /\s*,\s*/, $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; + for reverse split /\s*,\s*/, + $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; +} + +sub import { + shift; + return unless @_; + + my $pkg = caller; + + no strict 'refs'; + + for (@_) { + *{"$pkg\::WIN32"} = *WIN32 if $_ eq "WIN32"; + } } my @models = ( [EV:: => AnyEvent::Impl::EV::], [Event:: => AnyEvent::Impl::Event::], - [Tk:: => AnyEvent::Impl::Tk::], - [Wx:: => AnyEvent::Impl::POE::], - [Prima:: => AnyEvent::Impl::POE::], [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], - # everything below here will not be autoprobed as the pureperl backend should work everywhere - [Glib:: => AnyEvent::Impl::Glib::], + # everything below here will not be autoprobed + # as the pureperl backend should work everywhere + # and is usually faster + [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles + [Glib:: => AnyEvent::Impl::Glib::], # becomes extremely slow with many watchers [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy [Qt:: => AnyEvent::Impl::Qt::], # requires special main program [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza + [Wx:: => AnyEvent::Impl::POE::], + [Prima:: => AnyEvent::Impl::POE::], ); our %method = map +($_ => 1), qw(io timer signal child condvar one_event DESTROY); @@ -785,6 +815,7 @@ sub detect() { unless ($MODEL) { no strict 'refs'; + local $SIG{__DIE__}; if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) { my $model = "AnyEvent::Impl::$1"; @@ -917,7 +948,7 @@ $PID_CB{$pid}{$arg{cb}} = $arg{cb}; unless ($WNOHANG) { - $WNOHANG = eval { require POSIX; &POSIX::WNOHANG } || 1; + $WNOHANG = eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1; } unless ($CHLD_W) {