… | |
… | |
934 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
934 | Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model |
935 | if necessary. You should only call this function right before you would |
935 | if necessary. You should only call this function right before you would |
936 | have created an AnyEvent watcher anyway, that is, as late as possible at |
936 | have created an AnyEvent watcher anyway, that is, as late as possible at |
937 | runtime, and not e.g. during initialisation of your module. |
937 | runtime, and not e.g. during initialisation of your module. |
938 | |
938 | |
|
|
939 | The effect of calling this function is as if a watcher had been created |
|
|
940 | (specifically, actions that happen "when the first watcher is created" |
|
|
941 | happen when calling detetc as well). |
|
|
942 | |
939 | If you need to do some initialisation before AnyEvent watchers are |
943 | If you need to do some initialisation before AnyEvent watchers are |
940 | created, use C<post_detect>. |
944 | created, use C<post_detect>. |
941 | |
945 | |
942 | =item $guard = AnyEvent::post_detect { BLOCK } |
946 | =item $guard = AnyEvent::post_detect { BLOCK } |
943 | |
947 | |
… | |
… | |
1202 | |
1206 | |
1203 | BEGIN { AnyEvent::common_sense } |
1207 | BEGIN { AnyEvent::common_sense } |
1204 | |
1208 | |
1205 | use Carp (); |
1209 | use Carp (); |
1206 | |
1210 | |
1207 | our $VERSION = '5.34'; |
1211 | our $VERSION = '6.01'; |
1208 | our $MODEL; |
1212 | our $MODEL; |
1209 | |
1213 | |
1210 | our @ISA; |
1214 | our @ISA; |
1211 | |
1215 | |
1212 | our @REGISTRY; |
1216 | our @REGISTRY; |
… | |
… | |
1288 | [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # a bitch to autodetect |
1292 | [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # a bitch to autodetect |
1289 | [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::], |
1293 | [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::], |
1290 | [FLTK:: => AnyEvent::Impl::FLTK2::], |
1294 | [FLTK:: => AnyEvent::Impl::FLTK2::], |
1291 | ); |
1295 | ); |
1292 | |
1296 | |
|
|
1297 | our @isa_hook; |
|
|
1298 | |
|
|
1299 | sub _isa_set { |
|
|
1300 | my @pkg = ("AnyEvent", (map $_->[0], grep defined, @isa_hook), $MODEL); |
|
|
1301 | |
|
|
1302 | @{"$pkg[$_-1]::ISA"} = $pkg[$_] |
|
|
1303 | for 1 .. $#pkg; |
|
|
1304 | |
|
|
1305 | grep $_ && $_->[1], @isa_hook |
|
|
1306 | and AE::_reset (); |
|
|
1307 | } |
|
|
1308 | |
|
|
1309 | # used for hooking AnyEvent::Strict and AnyEvent::Debug::Wrap into the class hierarchy |
|
|
1310 | sub _isa_hook($$;$) { |
|
|
1311 | my ($i, $pkg, $reset_ae) = @_; |
|
|
1312 | |
|
|
1313 | $isa_hook[$i] = $pkg ? [$pkg, $reset_ae] : undef; |
|
|
1314 | |
|
|
1315 | _isa_set; |
|
|
1316 | } |
|
|
1317 | |
1293 | # all autoloaded methods reserve the complete glob, not just the method slot. |
1318 | # all autoloaded methods reserve the complete glob, not just the method slot. |
1294 | # due to bugs in perls method cache implementation. |
1319 | # due to bugs in perls method cache implementation. |
1295 | our @methods = qw(io timer time now now_update signal child idle condvar); |
1320 | our @methods = qw(io timer time now now_update signal child idle condvar); |
1296 | |
1321 | |
1297 | sub detect() { |
1322 | sub detect() { |
|
|
1323 | return $MODEL if $MODEL; # some programs keep references to detect |
|
|
1324 | |
1298 | local $!; # for good measure |
1325 | local $!; # for good measure |
1299 | local $SIG{__DIE__}; # we use eval |
1326 | local $SIG{__DIE__}; # we use eval |
1300 | |
1327 | |
1301 | # free some memory |
1328 | # free some memory |
1302 | *detect = sub () { $MODEL }; |
1329 | *detect = sub () { $MODEL }; |
… | |
… | |
1356 | # free memory only needed for probing |
1383 | # free memory only needed for probing |
1357 | undef @models; |
1384 | undef @models; |
1358 | undef @REGISTRY; |
1385 | undef @REGISTRY; |
1359 | |
1386 | |
1360 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
1387 | push @{"$MODEL\::ISA"}, "AnyEvent::Base"; |
1361 | unshift @ISA, $MODEL; |
|
|
1362 | |
1388 | |
1363 | # now nuke some methods that are overridden by the backend. |
1389 | # now nuke some methods that are overridden by the backend. |
1364 | # SUPER usage is not allowed in these. |
1390 | # SUPER usage is not allowed in these. |
1365 | for (qw(time signal child idle)) { |
1391 | for (qw(time signal child idle)) { |
1366 | undef &{"AnyEvent::Base::$_"} |
1392 | undef &{"AnyEvent::Base::$_"} |
1367 | if defined &{"$MODEL\::$_"}; |
1393 | if defined &{"$MODEL\::$_"}; |
1368 | } |
1394 | } |
1369 | |
1395 | |
|
|
1396 | _isa_set; |
|
|
1397 | |
1370 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
1398 | if ($ENV{PERL_ANYEVENT_STRICT}) { |
1371 | require AnyEvent::Strict; |
1399 | require AnyEvent::Strict; |
1372 | } |
1400 | } |
1373 | |
1401 | |
1374 | if ($ENV{PERL_ANYEVENT_DEBUG_WRAP}) { |
1402 | if ($ENV{PERL_ANYEVENT_DEBUG_WRAP}) { |
… | |
… | |
1378 | |
1406 | |
1379 | if (exists $ENV{PERL_ANYEVENT_DEBUG_SHELL}) { |
1407 | if (exists $ENV{PERL_ANYEVENT_DEBUG_SHELL}) { |
1380 | require AnyEvent::Socket; |
1408 | require AnyEvent::Socket; |
1381 | require AnyEvent::Debug; |
1409 | require AnyEvent::Debug; |
1382 | |
1410 | |
|
|
1411 | my $shell = $ENV{PERL_ANYEVENT_DEBUG_SHELL}; |
|
|
1412 | $shell =~ s/\$\$/$$/g; |
|
|
1413 | |
1383 | my ($host, $service) = AnyEvent::Socket::parse_hostport ($ENV{PERL_ANYEVENT_DEBUG_SHELL}); |
1414 | my ($host, $service) = AnyEvent::Socket::parse_hostport ($shell); |
1384 | $AnyEvent::Debug::SHELL = AnyEvent::Debug::shell ($host, $service); |
1415 | $AnyEvent::Debug::SHELL = AnyEvent::Debug::shell ($host, $service); |
1385 | } |
1416 | } |
1386 | |
1417 | |
1387 | (shift @post_detect)->() while @post_detect; |
1418 | (shift @post_detect)->() while @post_detect; |
1388 | undef @post_detect; |
1419 | undef @post_detect; |
… | |
… | |
1492 | sub time { |
1523 | sub time { |
1493 | eval q{ # poor man's autoloading {} |
1524 | eval q{ # poor man's autoloading {} |
1494 | # probe for availability of Time::HiRes |
1525 | # probe for availability of Time::HiRes |
1495 | if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { |
1526 | if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { |
1496 | warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8; |
1527 | warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8; |
|
|
1528 | *time = sub { Time::HiRes::time () }; |
1497 | *AE::time = \&Time::HiRes::time; |
1529 | *AE::time = \& Time::HiRes::time ; |
1498 | # if (eval "use POSIX (); (POSIX::times())... |
1530 | # if (eval "use POSIX (); (POSIX::times())... |
1499 | } else { |
1531 | } else { |
1500 | warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE; |
1532 | warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE; |
|
|
1533 | *time = sub { CORE::time }; |
1501 | *AE::time = sub (){ time }; # epic fail |
1534 | *AE::time = sub (){ CORE::time }; |
1502 | } |
1535 | } |
1503 | |
1536 | |
1504 | *time = sub { AE::time }; # different prototypes |
1537 | *now = \&time; |
1505 | }; |
1538 | }; |
1506 | die if $@; |
1539 | die if $@; |
1507 | |
1540 | |
1508 | &time |
1541 | &time |
1509 | } |
1542 | } |
1510 | |
1543 | |
1511 | *now = \&time; |
1544 | *now = \&time; |
1512 | |
|
|
1513 | sub now_update { } |
1545 | sub now_update { } |
1514 | |
1546 | |
1515 | sub _poll { |
1547 | sub _poll { |
1516 | Carp::croak "$AnyEvent::MODEL does not support blocking waits. Caught"; |
1548 | Carp::croak "$AnyEvent::MODEL does not support blocking waits. Caught"; |
1517 | } |
1549 | } |
… | |
… | |
1955 | C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs |
1987 | C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs |
1956 | can be very useful, however. |
1988 | can be very useful, however. |
1957 | |
1989 | |
1958 | =item C<PERL_ANYEVENT_DEBUG_SHELL> |
1990 | =item C<PERL_ANYEVENT_DEBUG_SHELL> |
1959 | |
1991 | |
1960 | If this env variable is set, then its contents will be |
1992 | If this env variable is set, then its contents will be interpreted by |
1961 | interpreted by C<AnyEvent::Socket::parse_hostport> and an |
1993 | C<AnyEvent::Socket::parse_hostport> (after replacing every occurance of |
1962 | C<AnyEvent::Debug::shell> is bound on that port. The shell object is saved |
1994 | C<$$> by the process pid) and an C<AnyEvent::Debug::shell> is bound on |
1963 | in C<$AnyEvent::Debug::SHELL>. |
1995 | that port. The shell object is saved in C<$AnyEvent::Debug::SHELL>. |
|
|
1996 | |
|
|
1997 | This takes place when the first watcher is created. |
1964 | |
1998 | |
1965 | For example, to bind a debug shell on a unix domain socket in |
1999 | For example, to bind a debug shell on a unix domain socket in |
1966 | F</tmp/debug.sock>, you could use this: |
2000 | F<< /tmp/debug<pid>.sock >>, you could use this: |
1967 | |
2001 | |
1968 | PERL_ANYEVENT_DEBUG_SHELL=unix/:/tmp/debug.sock perlprog |
2002 | PERL_ANYEVENT_DEBUG_SHELL=/tmp/debug\$\$.sock perlprog |
|
|
2003 | |
|
|
2004 | Note that creating sockets in F</tmp> is very unsafe on multiuser |
|
|
2005 | systems. |
1969 | |
2006 | |
1970 | =item C<PERL_ANYEVENT_DEBUG_WRAP> |
2007 | =item C<PERL_ANYEVENT_DEBUG_WRAP> |
1971 | |
2008 | |
1972 | Can be set to C<0>, C<1> or C<2> and enables wrapping of all watchers for |
2009 | Can be set to C<0>, C<1> or C<2> and enables wrapping of all watchers for |
1973 | debugging purposes. See C<AnyEvent::Debug::wrap> for details. |
2010 | debugging purposes. See C<AnyEvent::Debug::wrap> for details. |
… | |
… | |
2385 | (even when used without AnyEvent), but most event loops have acceptable |
2422 | (even when used without AnyEvent), but most event loops have acceptable |
2386 | performance with or without AnyEvent. |
2423 | performance with or without AnyEvent. |
2387 | |
2424 | |
2388 | =item * The overhead AnyEvent adds is usually much smaller than the overhead of |
2425 | =item * The overhead AnyEvent adds is usually much smaller than the overhead of |
2389 | the actual event loop, only with extremely fast event loops such as EV |
2426 | the actual event loop, only with extremely fast event loops such as EV |
2390 | adds AnyEvent significant overhead. |
2427 | does AnyEvent add significant overhead. |
2391 | |
2428 | |
2392 | =item * You should avoid POE like the plague if you want performance or |
2429 | =item * You should avoid POE like the plague if you want performance or |
2393 | reasonable memory usage. |
2430 | reasonable memory usage. |
2394 | |
2431 | |
2395 | =back |
2432 | =back |