AnyEvent
view release on metacpan or search on metacpan
lib/AnyEvent.pm view on Meta::CPAN
$VERBOSE = length $ENV{PERL_ANYEVENT_VERBOSE} ? $ENV{PERL_ANYEVENT_VERBOSE}*1 : 4;
my $idx;
$PROTOCOL{$_} = ++$idx
for reverse split /\s*,\s*/,
$ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6";
}
our @post_detect;
sub post_detect(&) {
my ($cb) = @_;
push @post_detect, $cb;
defined wantarray
? bless \$cb, "AnyEvent::Util::postdetect"
: ()
}
sub AnyEvent::Util::postdetect::DESTROY {
@post_detect = grep $_ != ${$_[0]}, @post_detect;
}
our $POSTPONE_W;
our @POSTPONE;
sub _postpone_exec {
undef $POSTPONE_W;
&{ shift @POSTPONE }
while @POSTPONE;
}
sub postpone(&) {
push @POSTPONE, shift;
$POSTPONE_W ||= AE::timer (0, 0, \&_postpone_exec);
()
}
sub log($$;@) {
# only load the big bloated module when we actually are about to log something
if ($_[0] <= ($VERBOSE || 1)) { # also catches non-numeric levels(!) and fatal
local ($!, $@);
require AnyEvent::Log; # among other things, sets $VERBOSE to 9
# AnyEvent::Log overwrites this function
goto &log;
}
0 # not logged
}
sub _logger($;$) {
my ($level, $renabled) = @_;
$$renabled = $level <= $VERBOSE;
my $logger = [(caller)[0], $level, $renabled];
$AnyEvent::Log::LOGGER{$logger+0} = $logger;
# return unless defined wantarray;
#
# require AnyEvent::Util;
# my $guard = AnyEvent::Util::guard (sub {
# # "clean up"
# delete $LOGGER{$logger+0};
# });
#
# sub {
# return 0 unless $$renabled;
#
# $guard if 0; # keep guard alive, but don't cause runtime overhead
# require AnyEvent::Log unless $AnyEvent::Log::VERSION;
# package AnyEvent::Log;
# _log ($logger->[0], $level, @_) # logger->[0] has been converted at load time
# }
}
if (length $ENV{PERL_ANYEVENT_LOG}) {
require AnyEvent::Log; # AnyEvent::Log does the thing for us
}
BEGIN {
*_fh_nonblocking = AnyEvent::WIN32
? sub($$) {
ioctl $_[0], 0x8004667e, pack "L", $_[1]; # FIONBIO
}
: sub($$) {
fcntl $_[0], AnyEvent::F_SETFL, $_[1] ? AnyEvent::O_NONBLOCK : 0;
}
;
}
sub fh_block($) {
_fh_nonblocking shift, 0
}
sub fh_unblock($) {
_fh_nonblocking shift, 1
}
our @models = (
[EV:: => AnyEvent::Impl::EV::],
[AnyEvent::Loop:: => AnyEvent::Impl::Perl::],
# everything below here will not (normally) be autoprobed
# as the pure perl backend should work everywhere
# and is usually faster
[Irssi:: => AnyEvent::Impl::Irssi::], # Irssi has a bogus "Event" package, so msut be near the top
[Event:: => AnyEvent::Impl::Event::], # slow, stable
[Glib:: => AnyEvent::Impl::Glib::], # becomes extremely slow with many watchers
# everything below here should not be autoloaded
[Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy
[Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles
[UV:: => AnyEvent::Impl::UV::], # switched from libev, added back all bugs imaginable
[Qt:: => AnyEvent::Impl::Qt::], # requires special main program
[POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza
[Wx:: => AnyEvent::Impl::POE::],
( run in 1.454 second using v1.01-cache-2.11-cpan-5735350b133 )