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.316 by root, Mon Mar 15 18:51:30 2010 UTC vs.
Revision 1.317 by root, Wed Mar 24 21:22:57 2010 UTC

1169our $VERBOSE; 1169our $VERBOSE;
1170 1170
1171BEGIN { 1171BEGIN {
1172 require "AnyEvent/constants.pl"; 1172 require "AnyEvent/constants.pl";
1173 1173
1174 eval "sub TAINT (){" . (${^TAINT} *1) . "}"; 1174 eval "sub TAINT (){" . (${^TAINT}*1) . "}";
1175 1175
1176 delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV} 1176 delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV}
1177 if ${^TAINT}; 1177 if ${^TAINT};
1178 1178
1179 $VERBOSE = $ENV{PERL_ANYEVENT_VERBOSE}*1; 1179 $VERBOSE = $ENV{PERL_ANYEVENT_VERBOSE}*1;
1222our @post_detect; 1222our @post_detect;
1223 1223
1224sub post_detect(&) { 1224sub post_detect(&) {
1225 my ($cb) = @_; 1225 my ($cb) = @_;
1226 1226
1227 if ($MODEL) {
1228 $cb->();
1229
1230 undef
1231 } else {
1232 push @post_detect, $cb; 1227 push @post_detect, $cb;
1233 1228
1234 defined wantarray 1229 defined wantarray
1235 ? bless \$cb, "AnyEvent::Util::postdetect" 1230 ? bless \$cb, "AnyEvent::Util::postdetect"
1236 : () 1231 : ()
1237 }
1238} 1232}
1239 1233
1240sub AnyEvent::Util::postdetect::DESTROY { 1234sub AnyEvent::Util::postdetect::DESTROY {
1241 @post_detect = grep $_ != ${$_[0]}, @post_detect; 1235 @post_detect = grep $_ != ${$_[0]}, @post_detect;
1242} 1236}
1295 @models = (); # free probe data 1289 @models = (); # free probe data
1296 1290
1297 push @{"$MODEL\::ISA"}, "AnyEvent::Base"; 1291 push @{"$MODEL\::ISA"}, "AnyEvent::Base";
1298 unshift @ISA, $MODEL; 1292 unshift @ISA, $MODEL;
1299 1293
1294 # now nuke some methods that are overriden by the backend.
1295 # SUPER is not allowed.
1296 for (qw(time signal child idle)) {
1297 undef &{"AnyEvent::Base::$_"}
1298 if defined &{"$MODEL\::$_"};
1299 }
1300
1300 require AnyEvent::Strict if $ENV{PERL_ANYEVENT_STRICT}; 1301 require AnyEvent::Strict if $ENV{PERL_ANYEVENT_STRICT};
1301 1302
1302 (shift @post_detect)->() while @post_detect; 1303 (shift @post_detect)->() while @post_detect;
1304
1305 *post_detect = sub(&) {
1306 shift->();
1307
1308 undef
1309 };
1303 1310
1304 $MODEL 1311 $MODEL
1305} 1312}
1306 1313
1307sub AUTOLOAD { 1314sub AUTOLOAD {
1385 1392
1386package AnyEvent::Base; 1393package AnyEvent::Base;
1387 1394
1388# default implementations for many methods 1395# default implementations for many methods
1389 1396
1390sub _time() { 1397sub time {
1391 eval q{ # poor man's autoloading 1398 eval q{ # poor man's autoloading {}
1392 # probe for availability of Time::HiRes 1399 # probe for availability of Time::HiRes
1393 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { 1400 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") {
1394 warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8; 1401 warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8;
1395 *_time = \&Time::HiRes::time; 1402 *AE::time = \&Time::HiRes::time;
1396 # if (eval "use POSIX (); (POSIX::times())... 1403 # if (eval "use POSIX (); (POSIX::times())...
1397 } else { 1404 } else {
1398 warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE; 1405 warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE;
1399 *_time = sub (){ time }; # epic fail 1406 *AE::time = sub (){ time }; # epic fail
1400 } 1407 }
1408
1409 *time = sub { AE::time }; # different prototypes
1401 }; 1410 };
1402 die if $@; 1411 die if $@;
1403 1412
1404 &_time 1413 &time
1405} 1414}
1406 1415
1407sub time { _time } 1416*now = \&time;
1408sub now { _time } 1417
1409sub now_update { } 1418sub now_update { }
1410 1419
1411# default implementation for ->condvar 1420# default implementation for ->condvar
1412 1421
1413sub condvar { 1422sub condvar {
1423 eval q{ # poor man's autoloading {}
1424 *condvar = sub {
1414 bless { @_ == 3 ? (_ae_cb => $_[2]) : () }, "AnyEvent::CondVar" 1425 bless { @_ == 3 ? (_ae_cb => $_[2]) : () }, "AnyEvent::CondVar"
1426 };
1427
1428 *AE::cv = sub (;&) {
1429 bless { @_ ? (_ae_cb => shift) : () }, "AnyEvent::CondVar"
1430 };
1431 };
1432 die if $@;
1433
1434 &condvar
1415} 1435}
1416 1436
1417# default implementation for ->signal 1437# default implementation for ->signal
1418 1438
1419our $HAVE_ASYNC_INTERRUPT; 1439our $HAVE_ASYNC_INTERRUPT;
1449 undef $SIG_TW 1469 undef $SIG_TW
1450 unless --$SIG_COUNT; 1470 unless --$SIG_COUNT;
1451} 1471}
1452 1472
1453our $_sig_name_init; $_sig_name_init = sub { 1473our $_sig_name_init; $_sig_name_init = sub {
1454 eval q{ # poor man's autoloading 1474 eval q{ # poor man's autoloading {}
1455 undef $_sig_name_init; 1475 undef $_sig_name_init;
1456 1476
1457 if (_have_async_interrupt) { 1477 if (_have_async_interrupt) {
1458 *sig2num = \&Async::Interrupt::sig2num; 1478 *sig2num = \&Async::Interrupt::sig2num;
1459 *sig2name = \&Async::Interrupt::sig2name; 1479 *sig2name = \&Async::Interrupt::sig2name;
1513 or Carp::croak "AnyEvent: unable to create a signal reporting pipe: $!\n"; 1533 or Carp::croak "AnyEvent: unable to create a signal reporting pipe: $!\n";
1514 1534
1515 $SIG_IO = AE::io $SIGPIPE_R, 0, \&_signal_exec; 1535 $SIG_IO = AE::io $SIGPIPE_R, 0, \&_signal_exec;
1516 } 1536 }
1517 1537
1518 *signal = sub { 1538 *signal = $HAVE_ASYNC_INTERRUPT
1539 ? sub {
1519 my (undef, %arg) = @_; 1540 my (undef, %arg) = @_;
1520 1541
1521 my $signal = uc $arg{signal}
1522 or Carp::croak "required option 'signal' is missing";
1523
1524 if ($HAVE_ASYNC_INTERRUPT) {
1525 # async::interrupt 1542 # async::interrupt
1526
1527 $signal = sig2num $signal; 1543 my $signal = sig2num $arg{signal};
1528 $SIG_CB{$signal}{$arg{cb}} = $arg{cb}; 1544 $SIG_CB{$signal}{$arg{cb}} = $arg{cb};
1529 1545
1530 $SIG_ASY{$signal} ||= new Async::Interrupt 1546 $SIG_ASY{$signal} ||= new Async::Interrupt
1531 cb => sub { undef $SIG_EV{$signal} }, 1547 cb => sub { undef $SIG_EV{$signal} },
1532 signal => $signal, 1548 signal => $signal,
1533 pipe => [$SIGPIPE_R->filenos], 1549 pipe => [$SIGPIPE_R->filenos],
1534 pipe_autodrain => 0, 1550 pipe_autodrain => 0,
1535 ; 1551 ;
1536 1552
1537 } else { 1553 bless [$signal, $arg{cb}], "AnyEvent::Base::signal"
1554 }
1555 : sub {
1556 my (undef, %arg) = @_;
1557
1538 # pure perl 1558 # pure perl
1539
1540 # AE::Util has been loaded in signal
1541 $signal = sig2name $signal; 1559 my $signal = sig2name $arg{signal};
1542 $SIG_CB{$signal}{$arg{cb}} = $arg{cb}; 1560 $SIG_CB{$signal}{$arg{cb}} = $arg{cb};
1543 1561
1544 $SIG{$signal} ||= sub { 1562 $SIG{$signal} ||= sub {
1545 local $!; 1563 local $!;
1546 syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV; 1564 syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV;
1547 undef $SIG_EV{$signal}; 1565 undef $SIG_EV{$signal};
1548 }; 1566 };
1549 1567
1550 # can't do signal processing without introducing races in pure perl, 1568 # can't do signal processing without introducing races in pure perl,
1551 # so limit the signal latency. 1569 # so limit the signal latency.
1552 _sig_add; 1570 _sig_add;
1553 }
1554 1571
1555 bless [$signal, $arg{cb}], "AnyEvent::Base::signal" 1572 bless [$signal, $arg{cb}], "AnyEvent::Base::signal"
1573 }
1556 }; 1574 ;
1557 1575
1558 *AnyEvent::Base::signal::DESTROY = sub { 1576 *AnyEvent::Base::signal::DESTROY = sub {
1559 my ($signal, $cb) = @{$_[0]}; 1577 my ($signal, $cb) = @{$_[0]};
1560 1578
1561 _sig_del; 1579 _sig_del;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines