… | |
… | |
1259 | @ENV{grep /^PERL_ANYEVENT_/, keys %ENV} = () |
1259 | @ENV{grep /^PERL_ANYEVENT_/, keys %ENV} = () |
1260 | if ${^TAINT}; |
1260 | if ${^TAINT}; |
1261 | |
1261 | |
1262 | # $ENV{PERL_ANYEVENT_xxx} now valid |
1262 | # $ENV{PERL_ANYEVENT_xxx} now valid |
1263 | |
1263 | |
1264 | $VERBOSE = length $ENV{PERL_ANYEVENT_VERBOSE} ? $ENV{PERL_ANYEVENT_VERBOSE}*1 : 3; |
1264 | $VERBOSE = length $ENV{PERL_ANYEVENT_VERBOSE} ? $ENV{PERL_ANYEVENT_VERBOSE}*1 : 4; |
1265 | |
1265 | |
1266 | my $idx; |
1266 | my $idx; |
1267 | $PROTOCOL{$_} = ++$idx |
1267 | $PROTOCOL{$_} = ++$idx |
1268 | for reverse split /\s*,\s*/, |
1268 | for reverse split /\s*,\s*/, |
1269 | $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; |
1269 | $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; |
… | |
… | |
1303 | () |
1303 | () |
1304 | } |
1304 | } |
1305 | |
1305 | |
1306 | sub log($$;@) { |
1306 | sub log($$;@) { |
1307 | # only load the big bloated module when we actually are about to log something |
1307 | # only load the big bloated module when we actually are about to log something |
1308 | if ($_[0] <= $VERBOSE) { # also catches non-numeric levels(!) |
1308 | if ($_[0] <= ($VERBOSE || 1)) { # also catches non-numeric levels(!) and fatal |
1309 | require AnyEvent::Log; |
1309 | require AnyEvent::Log; # among other things, sets $VERBOSE to 9 |
1310 | # AnyEvent::Log overwrites this function |
1310 | # AnyEvent::Log overwrites this function |
1311 | goto &log; |
1311 | goto &log; |
1312 | } |
1312 | } |
1313 | |
1313 | |
1314 | 0 # not logged |
1314 | 0 # not logged |
|
|
1315 | } |
|
|
1316 | |
|
|
1317 | sub logger($;$) { |
|
|
1318 | package AnyEvent::Log; |
|
|
1319 | |
|
|
1320 | my ($level, $renabled) = @_; |
|
|
1321 | |
|
|
1322 | $$renabled = $level <= $VERBOSE; |
|
|
1323 | |
|
|
1324 | my $pkg = (caller)[0]; |
|
|
1325 | |
|
|
1326 | my $logger = [$pkg, $level, $renabled]; |
|
|
1327 | |
|
|
1328 | our %LOGGER; |
|
|
1329 | $LOGGER{$logger+0} = $logger; |
|
|
1330 | |
|
|
1331 | require AnyEvent::Util; |
|
|
1332 | my $guard = AnyEvent::Util::guard (sub { |
|
|
1333 | # "clean up" |
|
|
1334 | delete $LOGGER{$logger+0}; |
|
|
1335 | }); |
|
|
1336 | |
|
|
1337 | sub { |
|
|
1338 | return 0 unless $$renabled; |
|
|
1339 | |
|
|
1340 | $guard if 0; # keep guard alive, but don't cause runtime overhead |
|
|
1341 | require AnyEvent::Log unless $AnyEvent::Log::VERSION; |
|
|
1342 | package AnyEvent::Log; |
|
|
1343 | _log ($logger->[0], $level, @_) # logger->[0] has been converted at load time |
|
|
1344 | } |
1315 | } |
1345 | } |
1316 | |
1346 | |
1317 | if (length $ENV{PERL_ANYEVENT_LOG}) { |
1347 | if (length $ENV{PERL_ANYEVENT_LOG}) { |
1318 | require AnyEvent::Log; # AnyEvent::Log does the thing for us |
1348 | require AnyEvent::Log; # AnyEvent::Log does the thing for us |
1319 | } |
1349 | } |
… | |
… | |
1384 | $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; |
1414 | $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; |
1385 | if (eval "require $model") { |
1415 | if (eval "require $model") { |
1386 | AnyEvent::log 7 => "loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it."; |
1416 | AnyEvent::log 7 => "loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it."; |
1387 | $MODEL = $model; |
1417 | $MODEL = $model; |
1388 | } else { |
1418 | } else { |
1389 | AnyEvent::log 5 => "unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@"; |
1419 | AnyEvent::log 4 => "unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@"; |
1390 | } |
1420 | } |
1391 | } |
1421 | } |
1392 | |
1422 | |
1393 | # check for already loaded models |
1423 | # check for already loaded models |
1394 | unless ($MODEL) { |
1424 | unless ($MODEL) { |
… | |
… | |
1418 | last; |
1448 | last; |
1419 | } |
1449 | } |
1420 | } |
1450 | } |
1421 | |
1451 | |
1422 | $MODEL |
1452 | $MODEL |
1423 | or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?"; |
1453 | or AnyEvent::log fatal => "AnyEvent: backend autodetection failed - did you properly install AnyEvent?"; |
1424 | } |
1454 | } |
1425 | } |
1455 | } |
1426 | |
1456 | |
1427 | # free memory only needed for probing |
1457 | # free memory only needed for probing |
1428 | undef @models; |
1458 | undef @models; |
… | |
… | |
2095 | C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs |
2125 | C<PERL_ANYEVENT_STRICT=1> in your environment while developing programs |
2096 | can be very useful, however. |
2126 | can be very useful, however. |
2097 | |
2127 | |
2098 | =item C<PERL_ANYEVENT_DEBUG_SHELL> |
2128 | =item C<PERL_ANYEVENT_DEBUG_SHELL> |
2099 | |
2129 | |
2100 | If this env variable is set, then its contents will be interpreted by |
2130 | If this env variable is nonempty, then its contents will be interpreted by |
2101 | C<AnyEvent::Socket::parse_hostport> (after replacing every occurance of |
2131 | C<AnyEvent::Socket::parse_hostport> and C<AnyEvent::Debug::shell> (after |
2102 | C<$$> by the process pid) and an C<AnyEvent::Debug::shell> is bound on |
2132 | replacing every occurance of C<$$> by the process pid). The shell object |
2103 | that port. The shell object is saved in C<$AnyEvent::Debug::SHELL>. |
2133 | is saved in C<$AnyEvent::Debug::SHELL>. |
2104 | |
2134 | |
2105 | This happens when the first watcher is created. |
2135 | This happens when the first watcher is created. |
2106 | |
2136 | |
2107 | For example, to bind a debug shell on a unix domain socket in |
2137 | For example, to bind a debug shell on a unix domain socket in |
2108 | F<< /tmp/debug<pid>.sock >>, you could use this: |
2138 | F<< /tmp/debug<pid>.sock >>, you could use this: |
2109 | |
2139 | |
2110 | PERL_ANYEVENT_DEBUG_SHELL=/tmp/debug\$\$.sock perlprog |
2140 | PERL_ANYEVENT_DEBUG_SHELL=/tmp/debug\$\$.sock perlprog |
|
|
2141 | # connect with e.g.: socat readline /tmp/debug123.sock |
2111 | |
2142 | |
|
|
2143 | Or to bind to tcp port 4545 on localhost: |
|
|
2144 | |
|
|
2145 | PERL_ANYEVENT_DEBUG_SHELL=127.0.0.1:4545 perlprog |
|
|
2146 | # connect with e.g.: telnet localhost 4545 |
|
|
2147 | |
2112 | Note that creating sockets in F</tmp> is very unsafe on multiuser |
2148 | Note that creating sockets in F</tmp> or on localhost is very unsafe on |
2113 | systems. |
2149 | multiuser systems. |
2114 | |
2150 | |
2115 | =item C<PERL_ANYEVENT_DEBUG_WRAP> |
2151 | =item C<PERL_ANYEVENT_DEBUG_WRAP> |
2116 | |
2152 | |
2117 | Can be set to C<0>, C<1> or C<2> and enables wrapping of all watchers for |
2153 | Can be set to C<0>, C<1> or C<2> and enables wrapping of all watchers for |
2118 | debugging purposes. See C<AnyEvent::Debug::wrap> for details. |
2154 | debugging purposes. See C<AnyEvent::Debug::wrap> for details. |