ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.358 by root, Sat Aug 13 02:35:32 2011 UTC vs.
Revision 1.362 by root, Sun Aug 14 01:57:18 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines