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.357 by root, Sat Aug 13 02:20:29 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}) {
1375 require AnyEvent::Debug; 1401 require AnyEvent::Debug;
1376 AnyEvent::Debug::wrap ($ENV{PERL_ANYEVENT_DEBUG_WRAP}); 1402 AnyEvent::Debug::wrap ($ENV{PERL_ANYEVENT_DEBUG_WRAP});
1377 } 1403 }
1378 1404
1379 if (exists $ENV{PERL_ANYEVENT_DEBUG_SHELL}) { 1405 if (exists $ENV{PERL_ANYEVENT_DEBUG_SHELL}) {
1406 require AnyEvent::Socket;
1380 require AnyEvent::Debug; 1407 require AnyEvent::Debug;
1381 #d# 1408
1409 my $shell = $ENV{PERL_ANYEVENT_DEBUG_SHELL};
1410 $shell =~ s/\$\$/$$/g;
1411
1412 my ($host, $service) = AnyEvent::Socket::parse_hostport ($shell);
1413 $AnyEvent::Debug::SHELL = AnyEvent::Debug::shell ($host, $service);
1382 } 1414 }
1383 1415
1384 (shift @post_detect)->() while @post_detect; 1416 (shift @post_detect)->() while @post_detect;
1385 undef @post_detect; 1417 undef @post_detect;
1386 1418
1489sub time { 1521sub time {
1490 eval q{ # poor man's autoloading {} 1522 eval q{ # poor man's autoloading {}
1491 # probe for availability of Time::HiRes 1523 # probe for availability of Time::HiRes
1492 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { 1524 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") {
1493 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 () };
1494 *AE::time = \&Time::HiRes::time; 1527 *AE::time = \& Time::HiRes::time ;
1495 # if (eval "use POSIX (); (POSIX::times())... 1528 # if (eval "use POSIX (); (POSIX::times())...
1496 } else { 1529 } else {
1497 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 };
1498 *AE::time = sub (){ time }; # epic fail 1532 *AE::time = sub (){ CORE::time };
1499 } 1533 }
1500 1534
1501 *time = sub { AE::time }; # different prototypes 1535 *now = \&time;
1502 }; 1536 };
1503 die if $@; 1537 die if $@;
1504 1538
1505 &time 1539 &time
1506} 1540}
1507 1541
1508*now = \&time; 1542*now = \&time;
1509
1510sub now_update { } 1543sub now_update { }
1511 1544
1512sub _poll { 1545sub _poll {
1513 Carp::croak "$AnyEvent::MODEL does not support blocking waits. Caught"; 1546 Carp::croak "$AnyEvent::MODEL does not support blocking waits. Caught";
1514} 1547}
1949 1982
1950Unlike C<use strict> (or its modern cousin, C<< use L<common::sense> 1983Unlike C<use strict> (or its modern cousin, C<< use L<common::sense>
1951>>, it is definitely recommended to keep it off in production. Keeping 1984>>, it is definitely recommended to keep it off in production. Keeping
1952C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs 1985C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs
1953can be very useful, however. 1986can be very useful, however.
1987
1988=item C<PERL_ANYEVENT_DEBUG_SHELL>
1989
1990If this env variable is set, then its contents will be interpreted by
1991C<AnyEvent::Socket::parse_hostport> (after replacing every occurance of
1992C<$$> by the process pid) and an C<AnyEvent::Debug::shell> is bound on
1993that port. The shell object is saved in C<$AnyEvent::Debug::SHELL>.
1994
1995This takes place when the first watcher is created.
1996
1997For example, to bind a debug shell on a unix domain socket in
1998F<< /tmp/debug<pid>.sock >>, you could use this:
1999
2000 PERL_ANYEVENT_DEBUG_SHELL=unix/:/tmp/debug\$\$.sock perlprog
2001
2002Note that creating sockets in F</tmp> is very unsafe on multiuser
2003systems.
2004
2005=item C<PERL_ANYEVENT_DEBUG_WRAP>
2006
2007Can be set to C<0>, C<1> or C<2> and enables wrapping of all watchers for
2008debugging purposes. See C<AnyEvent::Debug::wrap> for details.
1954 2009
1955=item C<PERL_ANYEVENT_MODEL> 2010=item C<PERL_ANYEVENT_MODEL>
1956 2011
1957This can be used to specify the event model to be used by AnyEvent, before 2012This can be used to specify the event model to be used by AnyEvent, before
1958auto detection and -probing kicks in. 2013auto detection and -probing kicks in.
2365(even when used without AnyEvent), but most event loops have acceptable 2420(even when used without AnyEvent), but most event loops have acceptable
2366performance with or without AnyEvent. 2421performance with or without AnyEvent.
2367 2422
2368=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
2369the 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
2370adds AnyEvent significant overhead. 2425does AnyEvent add significant overhead.
2371 2426
2372=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
2373reasonable memory usage. 2428reasonable memory usage.
2374 2429
2375=back 2430=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines