… | |
… | |
1205 | use Carp (); |
1205 | use Carp (); |
1206 | |
1206 | |
1207 | our $VERSION = '5.34'; |
1207 | our $VERSION = '5.34'; |
1208 | our $MODEL; |
1208 | our $MODEL; |
1209 | |
1209 | |
1210 | our $AUTOLOAD; |
|
|
1211 | our @ISA; |
1210 | our @ISA; |
1212 | |
1211 | |
1213 | our @REGISTRY; |
1212 | our @REGISTRY; |
1214 | |
1213 | |
1215 | our $VERBOSE; |
1214 | our $VERBOSE; |
… | |
… | |
1289 | [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # a bitch to autodetect |
1288 | [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # a bitch to autodetect |
1290 | [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::], |
1289 | [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::], |
1291 | [FLTK:: => AnyEvent::Impl::FLTK2::], |
1290 | [FLTK:: => AnyEvent::Impl::FLTK2::], |
1292 | ); |
1291 | ); |
1293 | |
1292 | |
|
|
1293 | # all autoloaded methods reserve the complete glob, not just the method slot. |
|
|
1294 | # due to bugs in perls method cache implementation. |
|
|
1295 | our @methods = qw(io timer time now now_update signal child idle condvar); |
|
|
1296 | |
1294 | sub detect() { |
1297 | sub detect() { |
|
|
1298 | local $!; # for good measure |
|
|
1299 | local $SIG{__DIE__}; # we use eval |
|
|
1300 | |
1295 | # free some memory |
1301 | # free some memory |
1296 | *detect = sub () { $MODEL }; |
1302 | *detect = sub () { $MODEL }; |
1297 | |
1303 | # undef &func doesn't correctly update the method cache. grmbl. |
1298 | local $!; # for good measure |
1304 | # so we delete the whole glob. grmbl. |
1299 | local $SIG{__DIE__}; |
1305 | # otoh, perl doesn't let me undef an active usb, but it lets me free |
|
|
1306 | # a glob with an active sub. hrm. i hope it works, but perl is |
|
|
1307 | # usually buggy in this department. sigh. |
|
|
1308 | delete @{"AnyEvent::"}{@methods}; |
|
|
1309 | undef @methods; |
1300 | |
1310 | |
1301 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z0-9:]+)$/) { |
1311 | if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z0-9:]+)$/) { |
1302 | my $model = $1; |
1312 | my $model = $1; |
1303 | $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; |
1313 | $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; |
1304 | if (eval "require $model") { |
1314 | if (eval "require $model") { |
… | |
… | |
1356 | undef &{"AnyEvent::Base::$_"} |
1366 | undef &{"AnyEvent::Base::$_"} |
1357 | if defined &{"$MODEL\::$_"}; |
1367 | if defined &{"$MODEL\::$_"}; |
1358 | } |
1368 | } |
1359 | |
1369 | |
1360 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
1370 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
1361 | eval { require AnyEvent::Strict }; |
1371 | require AnyEvent::Strict; |
1362 | warn "AnyEvent: cannot load AnyEvent::Strict: $@" |
1372 | } |
1363 | if $@ && $VERBOSE; |
1373 | |
|
|
1374 | if ($ENV{PERL_ANYEVENT_DEBUG_WRAP}) { |
|
|
1375 | require AnyEvent::Debug; |
|
|
1376 | AnyEvent::Debug::wrap ($ENV{PERL_ANYEVENT_DEBUG_WRAP}); |
|
|
1377 | } |
|
|
1378 | |
|
|
1379 | if (exists $ENV{PERL_ANYEVENT_DEBUG_SHELL}) { |
|
|
1380 | require AnyEvent::Debug; |
|
|
1381 | #d# |
1364 | } |
1382 | } |
1365 | |
1383 | |
1366 | (shift @post_detect)->() while @post_detect; |
1384 | (shift @post_detect)->() while @post_detect; |
1367 | undef @post_detect; |
1385 | undef @post_detect; |
1368 | |
1386 | |
… | |
… | |
1370 | shift->(); |
1388 | shift->(); |
1371 | |
1389 | |
1372 | undef |
1390 | undef |
1373 | }; |
1391 | }; |
1374 | |
1392 | |
1375 | # recover a few more bytes |
1393 | $MODEL |
1376 | postpone { |
1394 | } |
1377 | undef &AUTOLOAD; |
1395 | |
|
|
1396 | for my $name (@methods) { |
|
|
1397 | *$name = sub { |
|
|
1398 | detect; |
|
|
1399 | # we use goto because |
|
|
1400 | # a) it makes the thunk more transparent |
|
|
1401 | # b) it allows us to delete the thunk later |
|
|
1402 | goto &{ UNIVERSAL::can AnyEvent => "SUPER::$name" } |
1378 | }; |
1403 | }; |
1379 | |
|
|
1380 | $MODEL |
|
|
1381 | } |
|
|
1382 | |
|
|
1383 | our %method = map +($_ => 1), |
|
|
1384 | qw(io timer time now now_update signal child idle condvar DESTROY); |
|
|
1385 | |
|
|
1386 | sub AUTOLOAD { |
|
|
1387 | (my $func = $AUTOLOAD) =~ s/.*://; |
|
|
1388 | |
|
|
1389 | $method{$func} |
|
|
1390 | or Carp::croak "$func: not a valid AnyEvent class method"; |
|
|
1391 | |
|
|
1392 | # free some memory |
|
|
1393 | undef %method; |
|
|
1394 | |
|
|
1395 | detect; |
|
|
1396 | |
|
|
1397 | my $class = shift; |
|
|
1398 | $class->$func (@_); |
|
|
1399 | } |
1404 | } |
1400 | |
1405 | |
1401 | # utility function to dup a filehandle. this is used by many backends |
1406 | # utility function to dup a filehandle. this is used by many backends |
1402 | # to support binding more than one watcher per filehandle (they usually |
1407 | # to support binding more than one watcher per filehandle (they usually |
1403 | # allow only one watcher per fd, so we dup it to get a different one). |
1408 | # allow only one watcher per fd, so we dup it to get a different one). |
… | |
… | |
1427 | |
1432 | |
1428 | package AE; |
1433 | package AE; |
1429 | |
1434 | |
1430 | our $VERSION = $AnyEvent::VERSION; |
1435 | our $VERSION = $AnyEvent::VERSION; |
1431 | |
1436 | |
1432 | |
|
|
1433 | sub _reset() { |
1437 | sub _reset() { |
1434 | eval q{ |
1438 | eval q{ |
1435 | # fall back to the main API by default - backends and AnyEvent::Base |
1439 | # fall back to the main API by default - backends and AnyEvent::Base |
1436 | # implementations can overwrite these. |
1440 | # implementations can overwrite these. |
1437 | |
1441 | |
… | |
… | |
1450 | sub child($$) { |
1454 | sub child($$) { |
1451 | AnyEvent->child (pid => $_[0], cb => $_[1]) |
1455 | AnyEvent->child (pid => $_[0], cb => $_[1]) |
1452 | } |
1456 | } |
1453 | |
1457 | |
1454 | sub idle($) { |
1458 | sub idle($) { |
1455 | AnyEvent->idle (cb => $_[0]) |
1459 | AnyEvent->idle (cb => $_[0]); |
1456 | } |
1460 | } |
1457 | |
1461 | |
1458 | sub cv(;&) { |
1462 | sub cv(;&) { |
1459 | AnyEvent->condvar (@_ ? (cb => $_[0]) : ()) |
1463 | AnyEvent->condvar (@_ ? (cb => $_[0]) : ()) |
1460 | } |
1464 | } |