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.362 by root, Sun Aug 14 01:57:18 2011 UTC vs.
Revision 1.365 by root, Tue Aug 16 14:47:26 2011 UTC

1049It should use C<postpone>: 1049It should use C<postpone>:
1050 1050
1051 AnyEvent::postpone { $cb->(undef) }, return # signal error to callback, later 1051 AnyEvent::postpone { $cb->(undef) }, return # signal error to callback, later
1052 if $some_error_condition; 1052 if $some_error_condition;
1053 1053
1054=item AnyEvent::log $level, $msg[, @args]
1055
1056Log the given C<$msg> at the given C<$level>.
1057
1058Loads AnyEvent::Log on first use and calls C<AnyEvent::Log::log> -
1059consequently, look at the L<AnyEvent::Log> documentation for details.
1060
1054=back 1061=back
1055 1062
1056=head1 WHAT TO DO IN A MODULE 1063=head1 WHAT TO DO IN A MODULE
1057 1064
1058As a module author, you should C<use AnyEvent> and call AnyEvent methods 1065As a module author, you should C<use AnyEvent> and call AnyEvent methods
1224 1231
1225 delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV} 1232 delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV}
1226 if ${^TAINT}; 1233 if ${^TAINT};
1227 1234
1228 $VERBOSE = $ENV{PERL_ANYEVENT_VERBOSE}*1; 1235 $VERBOSE = $ENV{PERL_ANYEVENT_VERBOSE}*1;
1229
1230} 1236}
1231 1237
1232our $MAX_SIGNAL_LATENCY = 10; 1238our $MAX_SIGNAL_LATENCY = 10;
1233 1239
1234our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred 1240our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred
1270 push @POSTPONE, shift; 1276 push @POSTPONE, shift;
1271 1277
1272 $POSTPONE_W ||= AE::timer (0, 0, \&_postpone_exec); 1278 $POSTPONE_W ||= AE::timer (0, 0, \&_postpone_exec);
1273 1279
1274 () 1280 ()
1281}
1282
1283sub log($$;@) {
1284 require AnyEvent::Log;
1285 # AnyEvent::Log overwrites this function
1286 goto &log;
1275} 1287}
1276 1288
1277our @models = ( 1289our @models = (
1278 [EV:: => AnyEvent::Impl::EV:: , 1], 1290 [EV:: => AnyEvent::Impl::EV:: , 1],
1279 [AnyEvent::Loop:: => AnyEvent::Impl::Perl:: , 1], 1291 [AnyEvent::Loop:: => AnyEvent::Impl::Perl:: , 1],
1318# all autoloaded methods reserve the complete glob, not just the method slot. 1330# all autoloaded methods reserve the complete glob, not just the method slot.
1319# due to bugs in perls method cache implementation. 1331# due to bugs in perls method cache implementation.
1320our @methods = qw(io timer time now now_update signal child idle condvar); 1332our @methods = qw(io timer time now now_update signal child idle condvar);
1321 1333
1322sub detect() { 1334sub detect() {
1335 return $MODEL if $MODEL; # some programs keep references to detect
1336
1323 local $!; # for good measure 1337 local $!; # for good measure
1324 local $SIG{__DIE__}; # we use eval 1338 local $SIG{__DIE__}; # we use eval
1325 1339
1326 # free some memory 1340 # free some memory
1327 *detect = sub () { $MODEL }; 1341 *detect = sub () { $MODEL };
1336 if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z0-9:]+)$/) { 1350 if ($ENV{PERL_ANYEVENT_MODEL} =~ /^([a-zA-Z0-9:]+)$/) {
1337 my $model = $1; 1351 my $model = $1;
1338 $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//; 1352 $model = "AnyEvent::Impl::$model" unless $model =~ s/::$//;
1339 if (eval "require $model") { 1353 if (eval "require $model") {
1340 $MODEL = $model; 1354 $MODEL = $model;
1341 warn "AnyEvent: loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it.\n" if $VERBOSE >= 2; 1355 AnyEvent::log 7 => "loaded model '$model' (forced by \$ENV{PERL_ANYEVENT_MODEL}), using it."
1356 if $VERBOSE >= 7;
1342 } else { 1357 } else {
1343 warn "AnyEvent: unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@" if $VERBOSE; 1358 AnyEvent::log warn => "unable to load model '$model' (from \$ENV{PERL_ANYEVENT_MODEL}):\n$@";
1344 } 1359 }
1345 } 1360 }
1346 1361
1347 # check for already loaded models 1362 # check for already loaded models
1348 unless ($MODEL) { 1363 unless ($MODEL) {
1349 for (@REGISTRY, @models) { 1364 for (@REGISTRY, @models) {
1350 my ($package, $model) = @$_; 1365 my ($package, $model) = @$_;
1351 if (${"$package\::VERSION"} > 0) { 1366 if (${"$package\::VERSION"} > 0) {
1352 if (eval "require $model") { 1367 if (eval "require $model") {
1353 $MODEL = $model; 1368 $MODEL = $model;
1354 warn "AnyEvent: autodetected model '$model', using it.\n" if $VERBOSE >= 2; 1369 AnyEvent::log 7 => "autodetected model '$model', using it."
1370 if $VERBOSE >= 7;
1355 last; 1371 last;
1356 } 1372 }
1357 } 1373 }
1358 } 1374 }
1359 1375
1366 and eval "require $package" 1382 and eval "require $package"
1367 and ${"$package\::VERSION"} > 0 1383 and ${"$package\::VERSION"} > 0
1368 and eval "require $model" 1384 and eval "require $model"
1369 ) { 1385 ) {
1370 $MODEL = $model; 1386 $MODEL = $model;
1371 warn "AnyEvent: autoloaded model '$model', using it.\n" if $VERBOSE >= 2; 1387 AnyEvent::log 7 => "autoloaded model '$model', using it."
1388 if $VERBOSE >= 7;
1372 last; 1389 last;
1373 } 1390 }
1374 } 1391 }
1375 1392
1376 $MODEL 1393 $MODEL
1377 or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?\n"; 1394 or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?";
1378 } 1395 }
1379 } 1396 }
1380 1397
1381 # free memory only needed for probing 1398 # free memory only needed for probing
1382 undef @models; 1399 undef @models;
1506 sub time() { 1523 sub time() {
1507 AnyEvent->time 1524 AnyEvent->time
1508 } 1525 }
1509 1526
1510 *postpone = \&AnyEvent::postpone; 1527 *postpone = \&AnyEvent::postpone;
1528 *log = \&AnyEvent::log;
1511 }; 1529 };
1512 die if $@; 1530 die if $@;
1513} 1531}
1514 1532
1515BEGIN { _reset } 1533BEGIN { _reset }
1520 1538
1521sub time { 1539sub time {
1522 eval q{ # poor man's autoloading {} 1540 eval q{ # poor man's autoloading {}
1523 # probe for availability of Time::HiRes 1541 # probe for availability of Time::HiRes
1524 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") { 1542 if (eval "use Time::HiRes (); Time::HiRes::time (); 1") {
1525 warn "AnyEvent: using Time::HiRes for sub-second timing accuracy.\n" if $VERBOSE >= 8; 1543 AnyEvent::log 8 => "AnyEvent: using Time::HiRes for sub-second timing accuracy."
1544 if $AnyEvent::VERBOSE >= 8;
1526 *time = sub { Time::HiRes::time () }; 1545 *time = sub { Time::HiRes::time () };
1527 *AE::time = \& Time::HiRes::time ; 1546 *AE::time = \& Time::HiRes::time ;
1528 # if (eval "use POSIX (); (POSIX::times())... 1547 # if (eval "use POSIX (); (POSIX::times())...
1529 } else { 1548 } else {
1530 warn "AnyEvent: using built-in time(), WARNING, no sub-second resolution!\n" if $VERBOSE; 1549 AnyEvent::log critical => "using built-in time(), WARNING, no sub-second resolution!";
1531 *time = sub { CORE::time }; 1550 *time = sub { CORE::time };
1532 *AE::time = sub (){ CORE::time }; 1551 *AE::time = sub (){ CORE::time };
1533 } 1552 }
1534 1553
1535 *now = \&time; 1554 *now = \&time;
1633 1652
1634sub signal { 1653sub signal {
1635 eval q{ # poor man's autoloading {} 1654 eval q{ # poor man's autoloading {}
1636 # probe for availability of Async::Interrupt 1655 # probe for availability of Async::Interrupt
1637 if (_have_async_interrupt) { 1656 if (_have_async_interrupt) {
1638 warn "AnyEvent: using Async::Interrupt for race-free signal handling.\n" if $VERBOSE >= 8; 1657 AnyEvent::log 8 => "using Async::Interrupt for race-free signal handling."
1658 if $AnyEvent::VERBOSE >= 8;
1639 1659
1640 $SIGPIPE_R = new Async::Interrupt::EventPipe; 1660 $SIGPIPE_R = new Async::Interrupt::EventPipe;
1641 $SIG_IO = AE::io $SIGPIPE_R->fileno, 0, \&_signal_exec; 1661 $SIG_IO = AE::io $SIGPIPE_R->fileno, 0, \&_signal_exec;
1642 1662
1643 } else { 1663 } else {
1644 warn "AnyEvent: using emulated perl signal handling with latency timer.\n" if $VERBOSE >= 8; 1664 AnyEvent::log 8 => "using emulated perl signal handling with latency timer."
1665 if $AnyEvent::VERBOSE >= 8;
1645 1666
1646 if (AnyEvent::WIN32) { 1667 if (AnyEvent::WIN32) {
1647 require AnyEvent::Util; 1668 require AnyEvent::Util;
1648 1669
1649 ($SIGPIPE_R, $SIGPIPE_W) = AnyEvent::Util::portable_pipe (); 1670 ($SIGPIPE_R, $SIGPIPE_W) = AnyEvent::Util::portable_pipe ();
1958 1979
1959By default, AnyEvent will be completely silent except in fatal 1980By default, AnyEvent will be completely silent except in fatal
1960conditions. You can set this environment variable to make AnyEvent more 1981conditions. You can set this environment variable to make AnyEvent more
1961talkative. 1982talkative.
1962 1983
1963When set to C<1> or higher, causes AnyEvent to warn about unexpected 1984When set to C<5> or higher, causes AnyEvent to warn about unexpected
1964conditions, such as not being able to load the event model specified by 1985conditions, such as not being able to load the event model specified by
1965C<PERL_ANYEVENT_MODEL>. 1986C<PERL_ANYEVENT_MODEL>.
1966 1987
1967When set to C<2> or higher, cause AnyEvent to report to STDERR which event 1988When set to C<7> or higher, cause AnyEvent to report to STDERR which event
1968model it chooses. 1989model it chooses.
1969 1990
1970When set to C<8> or higher, then AnyEvent will report extra information on 1991When set to C<8> or higher, then AnyEvent will report extra information on
1971which optional modules it loads and how it implements certain features. 1992which optional modules it loads and how it implements certain features.
1972 1993
1995This takes place when the first watcher is created. 2016This takes place when the first watcher is created.
1996 2017
1997For example, to bind a debug shell on a unix domain socket in 2018For example, to bind a debug shell on a unix domain socket in
1998F<< /tmp/debug<pid>.sock >>, you could use this: 2019F<< /tmp/debug<pid>.sock >>, you could use this:
1999 2020
2000 PERL_ANYEVENT_DEBUG_SHELL=unix/:/tmp/debug\$\$.sock perlprog 2021 PERL_ANYEVENT_DEBUG_SHELL=/tmp/debug\$\$.sock perlprog
2001 2022
2002Note that creating sockets in F</tmp> is very unsafe on multiuser 2023Note that creating sockets in F</tmp> is very unsafe on multiuser
2003systems. 2024systems.
2004 2025
2005=item C<PERL_ANYEVENT_DEBUG_WRAP> 2026=item C<PERL_ANYEVENT_DEBUG_WRAP>
2805 2826
2806Tutorial/Introduction: L<AnyEvent::Intro>. 2827Tutorial/Introduction: L<AnyEvent::Intro>.
2807 2828
2808FAQ: L<AnyEvent::FAQ>. 2829FAQ: L<AnyEvent::FAQ>.
2809 2830
2810Utility functions: L<AnyEvent::Util>. 2831Utility functions: L<AnyEvent::Util> (misc. grab-bag), L<AnyEvent::Log>
2832(simply logging).
2811 2833
2834Development/Debugging: L<AnyEvent::Strict> (stricter checking),
2835L<AnyEvent::Debug> (interactive shell, watcher tracing).
2836
2812Event modules: L<AnyEvent::Loop>, L<EV>, L<EV::Glib>, L<Glib::EV>, 2837Supported event modules: L<AnyEvent::Loop>, L<EV>, L<EV::Glib>,
2813L<Event>, L<Glib::Event>, L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. 2838L<Glib::EV>, L<Event>, L<Glib::Event>, L<Glib>, L<Tk>, L<Event::Lib>,
2839L<Qt>, L<POE>, L<FLTK>.
2814 2840
2815Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, 2841Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>,
2816L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, 2842L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>,
2817L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, 2843L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>,
2818L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>, L<Anyevent::Impl::Irssi>. 2844L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>, L<Anyevent::Impl::Irssi>,
2845L<AnyEvent::Impl::FLTK>.
2819 2846
2820Non-blocking file handles, sockets, TCP clients and 2847Non-blocking handles, pipes, stream sockets, TCP clients and
2821servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>. 2848servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>.
2822 2849
2823Asynchronous DNS: L<AnyEvent::DNS>. 2850Asynchronous DNS: L<AnyEvent::DNS>.
2824 2851
2825Thread support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>. 2852Thread support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines