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.242 by root, Fri Jul 17 22:05:12 2009 UTC vs.
Revision 1.245 by root, Sat Jul 18 05:19:09 2009 UTC

1041 1041
1042=cut 1042=cut
1043 1043
1044package AnyEvent; 1044package AnyEvent;
1045 1045
1046# basically a tuned-down version of common::sense
1047sub common_sense {
1046no warnings; 1048 # no warnings
1049 ${^WARNING_BITS} ^= ${^WARNING_BITS};
1047use strict qw(vars subs); 1050 # use strict vars subs
1051 $^H |= 0x00000600;
1052}
1053
1054BEGIN { AnyEvent::common_sense }
1048 1055
1049use Carp (); 1056use Carp ();
1050 1057
1051our $VERSION = 4.83; 1058our $VERSION = 4.85;
1052our $MODEL; 1059our $MODEL;
1053 1060
1054our $AUTOLOAD; 1061our $AUTOLOAD;
1055our @ISA; 1062our @ISA;
1056 1063
1130 @post_detect = grep $_ != ${$_[0]}, @post_detect; 1137 @post_detect = grep $_ != ${$_[0]}, @post_detect;
1131} 1138}
1132 1139
1133sub detect() { 1140sub detect() {
1134 unless ($MODEL) { 1141 unless ($MODEL) {
1135 no strict 'refs';
1136 local $SIG{__DIE__}; 1142 local $SIG{__DIE__};
1137 1143
1138 if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) { 1144 if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z]+)$/) {
1139 my $model = "AnyEvent::Impl::$1"; 1145 my $model = "AnyEvent::Impl::$1";
1140 if (eval "require $model") { 1146 if (eval "require $model") {
1356 undef $SIG_TW 1362 undef $SIG_TW
1357 unless --$SIG_COUNT; 1363 unless --$SIG_COUNT;
1358 1364
1359 delete $SIG_CB{$signal}{$cb}; 1365 delete $SIG_CB{$signal}{$cb};
1360 1366
1367 $HAVE_ASYNC_INTERRUPT
1368 ? delete $SIG_ASY{$signal}
1361 # delete doesn't work with older perls - they then 1369 : # delete doesn't work with older perls - they then
1362 # print weird messages, or just unconditionally exit 1370 # print weird messages, or just unconditionally exit
1363 # instead of getting the default action. 1371 # instead of getting the default action.
1364 undef $SIG{$signal} 1372 undef $SIG{$signal}
1365 unless keys %{ $SIG_CB{$signal} }; 1373 unless keys %{ $SIG_CB{$signal} };
1366} 1374}
1367 1375
1368# default implementation for ->child 1376# default implementation for ->child
1369 1377
1386 defined (my $pid = $arg{pid} + 0) 1394 defined (my $pid = $arg{pid} + 0)
1387 or Carp::croak "required option 'pid' is missing"; 1395 or Carp::croak "required option 'pid' is missing";
1388 1396
1389 $PID_CB{$pid}{$arg{cb}} = $arg{cb}; 1397 $PID_CB{$pid}{$arg{cb}} = $arg{cb};
1390 1398
1399 # WNOHANG is almost cetrainly 1 everywhere
1400 $WNOHANG ||= $^O =~ /^(?:openbsd|netbsd|linux|freebsd|cygwin|MSWin32)$/
1401 ? 1
1391 $WNOHANG ||= eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1; 1402 : eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1;
1392 1403
1393 unless ($CHLD_W) { 1404 unless ($CHLD_W) {
1394 $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld); 1405 $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld);
1395 # child could be a zombie already, so make at least one round 1406 # child could be a zombie already, so make at least one round
1396 &_sigchld; 1407 &_sigchld;
1448 1459
1449our @ISA = AnyEvent::CondVar::Base::; 1460our @ISA = AnyEvent::CondVar::Base::;
1450 1461
1451package AnyEvent::CondVar::Base; 1462package AnyEvent::CondVar::Base;
1452 1463
1453use overload 1464#use overload
1454 '&{}' => sub { my $self = shift; sub { $self->send (@_) } }, 1465# '&{}' => sub { my $self = shift; sub { $self->send (@_) } },
1455 fallback => 1; 1466# fallback => 1;
1467
1468# save 300+ kilobytes by dirtily hardcoding overloading
1469${"AnyEvent::CondVar::Base::OVERLOAD"}{dummy}++; # Register with magic by touching.
1470*{'AnyEvent::CondVar::Base::()'} = sub { }; # "Make it findable via fetchmethod."
1471*{'AnyEvent::CondVar::Base::(&{}'} = sub { my $self = shift; sub { $self->send (@_) } }; # &{}
1472${'AnyEvent::CondVar::Base::()'} = 1; # fallback
1456 1473
1457our $WAITING; 1474our $WAITING;
1458 1475
1459sub _send { 1476sub _send {
1460 # nop 1477 # nop
1551C<PERL_ANYEVENT_MODEL>. 1568C<PERL_ANYEVENT_MODEL>.
1552 1569
1553When set to C<2> or higher, cause AnyEvent to report to STDERR which event 1570When set to C<2> or higher, cause AnyEvent to report to STDERR which event
1554model it chooses. 1571model it chooses.
1555 1572
1573When set to C<8> or higher, then AnyEvent will report extra information on
1574which optional modules it loads and how it implements certain features.
1575
1556=item C<PERL_ANYEVENT_STRICT> 1576=item C<PERL_ANYEVENT_STRICT>
1557 1577
1558AnyEvent does not do much argument checking by default, as thorough 1578AnyEvent does not do much argument checking by default, as thorough
1559argument checking is very costly. Setting this variable to a true value 1579argument checking is very costly. Setting this variable to a true value
1560will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly 1580will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly
1561check the arguments passed to most method calls. If it finds any problems, 1581check the arguments passed to most method calls. If it finds any problems,
1562it will croak. 1582it will croak.
1563 1583
1564In other words, enables "strict" mode. 1584In other words, enables "strict" mode.
1565 1585
1566Unlike C<use strict>, it is definitely recommended to keep it off in 1586Unlike C<use strict> (or it's modern cousin, C<< use L<common::sense>
1567production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while 1587>>, it is definitely recommended to keep it off in production. Keeping
1568developing programs can be very useful, however. 1588C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs
1589can be very useful, however.
1569 1590
1570=item C<PERL_ANYEVENT_MODEL> 1591=item C<PERL_ANYEVENT_MODEL>
1571 1592
1572This can be used to specify the event model to be used by AnyEvent, before 1593This can be used to specify the event model to be used by AnyEvent, before
1573auto detection and -probing kicks in. It must be a string consisting 1594auto detection and -probing kicks in. It must be a string consisting
1635 1656
1636When neither C<ca_file> nor C<ca_path> was specified during 1657When neither C<ca_file> nor C<ca_path> was specified during
1637L<AnyEvent::TLS> context creation, and either of these environment 1658L<AnyEvent::TLS> context creation, and either of these environment
1638variables exist, they will be used to specify CA certificate locations 1659variables exist, they will be used to specify CA certificate locations
1639instead of a system-dependent default. 1660instead of a system-dependent default.
1661
1662=item C<PERL_ANYEVENT_AVOID_GUARD> and C<PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT>
1663
1664When these are set to C<1>, then the respective modules are not
1665loaded. Mostly good for testing AnyEvent itself.
1640 1666
1641=back 1667=back
1642 1668
1643=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE 1669=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE
1644 1670

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines