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.338 by root, Tue Nov 23 04:45:59 2010 UTC vs.
Revision 1.345 by root, Fri Dec 31 04:50:44 2010 UTC

85that isn't them. What's worse, all the potential users of your 85that isn't them. What's worse, all the potential users of your
86module are I<also> forced to use the same event loop you use. 86module are I<also> forced to use the same event loop you use.
87 87
88AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works 88AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works
89fine. AnyEvent + Tk works fine etc. etc. but none of these work together 89fine. AnyEvent + Tk works fine etc. etc. but none of these work together
90with the rest: POE + IO::Async? No go. Tk + Event? No go. Again: if 90with the rest: POE + EV? No go. Tk + Event? No go. Again: if your module
91your module uses one of those, every user of your module has to use it, 91uses one of those, every user of your module has to use it, too. But if
92too. But if your module uses AnyEvent, it works transparently with all 92your module uses AnyEvent, it works transparently with all event models it
93event models it supports (including stuff like IO::Async, as long as those 93supports (including stuff like IO::Async, as long as those use one of the
94use one of the supported event loops. It is easy to add new event loops 94supported event loops. It is easy to add new event loops to AnyEvent, too,
95to AnyEvent, too, so it is future-proof). 95so it is future-proof).
96 96
97In addition to being free of having to use I<the one and only true event 97In addition to being free of having to use I<the one and only true event
98model>, AnyEvent also is free of bloat and policy: with POE or similar 98model>, AnyEvent also is free of bloat and policy: with POE or similar
99modules, you get an enormous amount of code and strict rules you have to 99modules, you get an enormous amount of code and strict rules you have to
100follow. AnyEvent, on the other hand, is lean and to the point, by only 100follow. AnyEvent, on the other hand, is lean and to the point, by only
876 AnyEvent::Impl::Glib based on Glib, slow but very stable. 876 AnyEvent::Impl::Glib based on Glib, slow but very stable.
877 AnyEvent::Impl::Tk based on Tk, very broken. 877 AnyEvent::Impl::Tk based on Tk, very broken.
878 AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. 878 AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse.
879 AnyEvent::Impl::POE based on POE, very slow, some limitations. 879 AnyEvent::Impl::POE based on POE, very slow, some limitations.
880 AnyEvent::Impl::Irssi used when running within irssi. 880 AnyEvent::Impl::Irssi used when running within irssi.
881 AnyEvent::Impl::IOAsync based on IO::Async.
882 AnyEvent::Impl::Cocoa based on Cocoa::EventLoop.
881 883
882=item Backends with special needs. 884=item Backends with special needs.
883 885
884Qt requires the Qt::Application to be instantiated first, but will 886Qt requires the Qt::Application to be instantiated first, but will
885otherwise be picked up automatically. As long as the main program 887otherwise be picked up automatically. As long as the main program
886instantiates the application before any AnyEvent watchers are created, 888instantiates the application before any AnyEvent watchers are created,
887everything should just work. 889everything should just work.
888 890
889 AnyEvent::Impl::Qt based on Qt. 891 AnyEvent::Impl::Qt based on Qt.
890
891Support for IO::Async can only be partial, as it is too broken and
892architecturally limited to even support the AnyEvent API. It also
893is the only event loop that needs the loop to be set explicitly, so
894it can only be used by a main program knowing about AnyEvent. See
895L<AnyEvent::Impl::IOAsync> for the gory details.
896
897 AnyEvent::Impl::IOAsync based on IO::Async, cannot be autoprobed.
898 892
899=item Event loops that are indirectly supported via other backends. 893=item Event loops that are indirectly supported via other backends.
900 894
901Some event loops can be supported via other modules: 895Some event loops can be supported via other modules:
902 896
1167 1161
1168BEGIN { AnyEvent::common_sense } 1162BEGIN { AnyEvent::common_sense }
1169 1163
1170use Carp (); 1164use Carp ();
1171 1165
1172our $VERSION = '5.29'; 1166our $VERSION = '5.3';
1173our $MODEL; 1167our $MODEL;
1174 1168
1175our $AUTOLOAD; 1169our $AUTOLOAD;
1176our @ISA; 1170our @ISA;
1177 1171
1215 [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles 1209 [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles
1216 [Qt:: => AnyEvent::Impl::Qt::], # requires special main program 1210 [Qt:: => AnyEvent::Impl::Qt::], # requires special main program
1217 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza 1211 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza
1218 [Wx:: => AnyEvent::Impl::POE::], 1212 [Wx:: => AnyEvent::Impl::POE::],
1219 [Prima:: => AnyEvent::Impl::POE::], 1213 [Prima:: => AnyEvent::Impl::POE::],
1220 # IO::Async is just too broken - we would need workarounds for its
1221 # byzantine signal and broken child handling, among others.
1222 # IO::Async is rather hard to detect, as it doesn't have any
1223 # obvious default class.
1224 [IO::Async:: => AnyEvent::Impl::IOAsync::], # requires special main program
1225 [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # requires special main program 1214 [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::],
1226 [IO::Async::Notifier:: => AnyEvent::Impl::IOAsync::], # requires special main program 1215 [Cocoa::EventLoop:: => AnyEvent::Impl::Cocoa::],
1227 [AnyEvent::Impl::IOAsync:: => AnyEvent::Impl::IOAsync::], # requires special main program
1228); 1216);
1229 1217
1230our %method = map +($_ => 1), 1218our %method = map +($_ => 1),
1231 qw(io timer time now now_update signal child idle condvar one_event DESTROY); 1219 qw(io timer time now now_update signal child idle condvar one_event DESTROY);
1232 1220
1307 for (qw(time signal child idle)) { 1295 for (qw(time signal child idle)) {
1308 undef &{"AnyEvent::Base::$_"} 1296 undef &{"AnyEvent::Base::$_"}
1309 if defined &{"$MODEL\::$_"}; 1297 if defined &{"$MODEL\::$_"};
1310 } 1298 }
1311 1299
1312 require AnyEvent::Strict if $ENV{PERL_ANYEVENT_STRICT}; 1300 if ($ENV{PERL_ANYEVENT_STRICT}) {
1301 eval { require AnyEvent::Strict };
1302 warn "AnyEvent: cannot load AnyEvent::Strict: $@"
1303 if $@ && $VERBOSE;
1304 }
1313 1305
1314 (shift @post_detect)->() while @post_detect; 1306 (shift @post_detect)->() while @post_detect;
1315 1307
1316 *post_detect = sub(&) { 1308 *post_detect = sub(&) {
1317 shift->(); 1309 shift->();
1624# default implementation for ->child 1616# default implementation for ->child
1625 1617
1626our %PID_CB; 1618our %PID_CB;
1627our $CHLD_W; 1619our $CHLD_W;
1628our $CHLD_DELAY_W; 1620our $CHLD_DELAY_W;
1629our $WNOHANG;
1630 1621
1631# used by many Impl's 1622# used by many Impl's
1632sub _emit_childstatus($$) { 1623sub _emit_childstatus($$) {
1633 my (undef, $rpid, $rstatus) = @_; 1624 my (undef, $rpid, $rstatus) = @_;
1634 1625
1641 eval q{ # poor man's autoloading {} 1632 eval q{ # poor man's autoloading {}
1642 *_sigchld = sub { 1633 *_sigchld = sub {
1643 my $pid; 1634 my $pid;
1644 1635
1645 AnyEvent->_emit_childstatus ($pid, $?) 1636 AnyEvent->_emit_childstatus ($pid, $?)
1646 while ($pid = waitpid -1, $WNOHANG) > 0; 1637 while ($pid = waitpid -1, WNOHANG) > 0;
1647 }; 1638 };
1648 1639
1649 *child = sub { 1640 *child = sub {
1650 my (undef, %arg) = @_; 1641 my (undef, %arg) = @_;
1651 1642
1652 defined (my $pid = $arg{pid} + 0) 1643 defined (my $pid = $arg{pid} + 0)
1653 or Carp::croak "required option 'pid' is missing"; 1644 or Carp::croak "required option 'pid' is missing";
1654 1645
1655 $PID_CB{$pid}{$arg{cb}} = $arg{cb}; 1646 $PID_CB{$pid}{$arg{cb}} = $arg{cb};
1656
1657 # WNOHANG is almost cetrainly 1 everywhere
1658 $WNOHANG ||= $^O =~ /^(?:openbsd|netbsd|linux|freebsd|cygwin|MSWin32)$/
1659 ? 1
1660 : eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1;
1661 1647
1662 unless ($CHLD_W) { 1648 unless ($CHLD_W) {
1663 $CHLD_W = AE::signal CHLD => \&_sigchld; 1649 $CHLD_W = AE::signal CHLD => \&_sigchld;
1664 # child could be a zombie already, so make at least one round 1650 # child could be a zombie already, so make at least one round
1665 &_sigchld; 1651 &_sigchld;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines