--- AnyEvent/lib/AnyEvent.pm 2011/08/12 00:53:29 1.355 +++ AnyEvent/lib/AnyEvent.pm 2011/08/13 02:35:32 1.358 @@ -880,7 +880,7 @@ AnyEvent::Impl::Irssi used when running within irssi. AnyEvent::Impl::IOAsync based on IO::Async. AnyEvent::Impl::Cocoa based on Cocoa::EventLoop. - AnyEvent::Impl::FLTK based on FLTK. + AnyEvent::Impl::FLTK2 based on FLTK (fltk 2 binding). =item Backends with special needs. @@ -1207,7 +1207,6 @@ our $VERSION = '5.34'; our $MODEL; -our $AUTOLOAD; our @ISA; our @REGISTRY; @@ -1288,18 +1287,26 @@ [Prima:: => AnyEvent::Impl::POE::], [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # a bitch to autodetect [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::], - [FLTK:: => AnyEvent::Impl::FLTK::], + [FLTK:: => AnyEvent::Impl::FLTK2::], ); -our %method = map +($_ => 1), - qw(io timer time now now_update signal child idle condvar DESTROY); +# all autoloaded methods reserve the complete glob, not just the method slot. +# due to bugs in perls method cache implementation. +our @methods = qw(io timer time now now_update signal child idle condvar); sub detect() { + local $!; # for good measure + local $SIG{__DIE__}; # we use eval + # free some memory *detect = sub () { $MODEL }; - - local $!; # for good measure - local $SIG{__DIE__}; + # undef &func doesn't correctly update the method cache. grmbl. + # so we delete the whole glob. grmbl. + # otoh, perl doesn't let me undef an active usb, but it lets me free + # a glob with an active sub. hrm. i hope it works, but perl is + # usually buggy in this department. sigh. + delete @{"AnyEvent::"}{@methods}; + undef @methods; if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z0-9:]+)$/) { my $model = $1; @@ -1361,9 +1368,20 @@ } if ($ENV{PERL_ANYEVENT_STRICT}) { - eval { require AnyEvent::Strict }; - warn "AnyEvent: cannot load AnyEvent::Strict: $@" - if $@ && $VERBOSE; + require AnyEvent::Strict; + } + + if ($ENV{PERL_ANYEVENT_DEBUG_WRAP}) { + require AnyEvent::Debug; + AnyEvent::Debug::wrap ($ENV{PERL_ANYEVENT_DEBUG_WRAP}); + } + + if (exists $ENV{PERL_ANYEVENT_DEBUG_SHELL}) { + require AnyEvent::Socket; + require AnyEvent::Debug; + + my ($host, $service) = AnyEvent::Socket::parse_hostport ($ENV{PERL_ANYEVENT_DEBUG_SHELL}); + $AnyEvent::Debug::SHELL = AnyEvent::Debug::shell ($host, $service); } (shift @post_detect)->() while @post_detect; @@ -1375,30 +1393,17 @@ undef }; - # recover a few more bytes - postpone { - undef &AUTOLOAD; - }; - $MODEL } -our %method = map +($_ => 1), - qw(io timer time now now_update signal child idle condvar DESTROY); - -sub AUTOLOAD { - (my $func = $AUTOLOAD) =~ s/.*://; - - $method{$func} - or Carp::croak "$func: not a valid AnyEvent class method"; - - # free some memory - undef %method; - - detect; - - my $class = shift; - $class->$func (@_); +for my $name (@methods) { + *$name = sub { + detect; + # we use goto because + # a) it makes the thunk more transparent + # b) it allows us to delete the thunk later + goto &{ UNIVERSAL::can AnyEvent => "SUPER::$name" } + }; } # utility function to dup a filehandle. this is used by many backends @@ -1432,7 +1437,6 @@ our $VERSION = $AnyEvent::VERSION; - sub _reset() { eval q{ # fall back to the main API by default - backends and AnyEvent::Base @@ -1455,7 +1459,7 @@ } sub idle($) { - AnyEvent->idle (cb => $_[0]) + AnyEvent->idle (cb => $_[0]); } sub cv(;&) { @@ -1770,9 +1774,9 @@ $rcb = sub { if ($cb) { - $w = _time; + $w = AE::time; &$cb; - $w = _time - $w; + $w = AE::time - $w; # never use more then 50% of the time for the idle watcher, # within some limits @@ -1951,6 +1955,23 @@ C in your environment while developing programs can be very useful, however. +=item C + +If this env variable is set, then its contents will be +interpreted by C and an +C is bound on that port. The shell object is saved +in C<$AnyEvent::Debug::SHELL>. + +For example, to bind a debug shell on a unix domain socket in +F, you could use this: + + PERL_ANYEVENT_DEBUG_SHELL=unix/:/tmp/debug.sock perlprog + +=item C + +Can be set to C<0>, C<1> or C<2> and enables wrapping of all watchers for +debugging purposes. See C for details. + =item C This can be used to specify the event model to be used by AnyEvent, before