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.243 by root, Fri Jul 17 23:12:20 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.83;
1052our $MODEL; 1059our $MODEL;
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") {
1386 defined (my $pid = $arg{pid} + 0) 1392 defined (my $pid = $arg{pid} + 0)
1387 or Carp::croak "required option 'pid' is missing"; 1393 or Carp::croak "required option 'pid' is missing";
1388 1394
1389 $PID_CB{$pid}{$arg{cb}} = $arg{cb}; 1395 $PID_CB{$pid}{$arg{cb}} = $arg{cb};
1390 1396
1397 # WNOHANG is almost cetrainly 1 everywhere
1398 $WNOHANG ||= $^O =~ /^(?:openbsd|netbsd|linux|freebsd|cygwin|MSWin32)$/
1399 ? 1
1391 $WNOHANG ||= eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1; 1400 : eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1;
1392 1401
1393 unless ($CHLD_W) { 1402 unless ($CHLD_W) {
1394 $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld); 1403 $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld);
1395 # child could be a zombie already, so make at least one round 1404 # child could be a zombie already, so make at least one round
1396 &_sigchld; 1405 &_sigchld;
1448 1457
1449our @ISA = AnyEvent::CondVar::Base::; 1458our @ISA = AnyEvent::CondVar::Base::;
1450 1459
1451package AnyEvent::CondVar::Base; 1460package AnyEvent::CondVar::Base;
1452 1461
1453use overload 1462#use overload
1454 '&{}' => sub { my $self = shift; sub { $self->send (@_) } }, 1463# '&{}' => sub { my $self = shift; sub { $self->send (@_) } },
1455 fallback => 1; 1464# fallback => 1;
1465
1466# save 300+ kilobytes by dirtily hardcoding overloading
1467${"AnyEvent::CondVar::Base::OVERLOAD"}{dummy}++; # Register with magic by touching.
1468*{'AnyEvent::CondVar::Base::()'} = sub { }; # "Make it findable via fetchmethod."
1469*{'AnyEvent::CondVar::Base::(&{}'} = sub { my $self = shift; sub { $self->send (@_) } }; # &{}
1470${'AnyEvent::CondVar::Base::()'} = 1; # fallback
1456 1471
1457our $WAITING; 1472our $WAITING;
1458 1473
1459sub _send { 1474sub _send {
1460 # nop 1475 # nop
1561check the arguments passed to most method calls. If it finds any problems, 1576check the arguments passed to most method calls. If it finds any problems,
1562it will croak. 1577it will croak.
1563 1578
1564In other words, enables "strict" mode. 1579In other words, enables "strict" mode.
1565 1580
1566Unlike C<use strict>, it is definitely recommended to keep it off in 1581Unlike C<use strict> (or it's modern cousin, C<< use L<common::sense>
1567production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while 1582>>, it is definitely recommended to keep it off in production. Keeping
1568developing programs can be very useful, however. 1583C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs
1584can be very useful, however.
1569 1585
1570=item C<PERL_ANYEVENT_MODEL> 1586=item C<PERL_ANYEVENT_MODEL>
1571 1587
1572This can be used to specify the event model to be used by AnyEvent, before 1588This 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 1589auto detection and -probing kicks in. It must be a string consisting

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines