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.332 by root, Tue Aug 31 23:32:40 2010 UTC vs.
Revision 1.342 by root, Wed Dec 29 04:16:33 2010 UTC

46in a tutorial or some gentle introduction, have a look at the 46in a tutorial or some gentle introduction, have a look at the
47L<AnyEvent::Intro> manpage. 47L<AnyEvent::Intro> manpage.
48 48
49=head1 SUPPORT 49=head1 SUPPORT
50 50
51An FAQ document is available as L<AnyEvent::FAQ>.
52
51There is a mailinglist for discussing all things AnyEvent, and an IRC 53There also is a mailinglist for discussing all things AnyEvent, and an IRC
52channel, too. 54channel, too.
53 55
54See the AnyEvent project page at the B<Schmorpforge Ta-Sa Software 56See the AnyEvent project page at the B<Schmorpforge Ta-Sa Software
55Repository>, at L<http://anyevent.schmorp.de>, for more info. 57Repository>, at L<http://anyevent.schmorp.de>, for more info.
56 58
874 AnyEvent::Impl::Glib based on Glib, slow but very stable. 876 AnyEvent::Impl::Glib based on Glib, slow but very stable.
875 AnyEvent::Impl::Tk based on Tk, very broken. 877 AnyEvent::Impl::Tk based on Tk, very broken.
876 AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. 878 AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse.
877 AnyEvent::Impl::POE based on POE, very slow, some limitations. 879 AnyEvent::Impl::POE based on POE, very slow, some limitations.
878 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.
879 882
880=item Backends with special needs. 883=item Backends with special needs.
881 884
882Qt requires the Qt::Application to be instantiated first, but will 885Qt requires the Qt::Application to be instantiated first, but will
883otherwise be picked up automatically. As long as the main program 886otherwise be picked up automatically. As long as the main program
884instantiates the application before any AnyEvent watchers are created, 887instantiates the application before any AnyEvent watchers are created,
885everything should just work. 888everything should just work.
886 889
887 AnyEvent::Impl::Qt based on Qt. 890 AnyEvent::Impl::Qt based on Qt.
888
889Support for IO::Async can only be partial, as it is too broken and
890architecturally limited to even support the AnyEvent API. It also
891is the only event loop that needs the loop to be set explicitly, so
892it can only be used by a main program knowing about AnyEvent. See
893L<AnyEvent::Impl::IOAsync> for the gory details.
894
895 AnyEvent::Impl::IOAsync based on IO::Async, cannot be autoprobed.
896 891
897=item Event loops that are indirectly supported via other backends. 892=item Event loops that are indirectly supported via other backends.
898 893
899Some event loops can be supported via other modules: 894Some event loops can be supported via other modules:
900 895
1165 1160
1166BEGIN { AnyEvent::common_sense } 1161BEGIN { AnyEvent::common_sense }
1167 1162
1168use Carp (); 1163use Carp ();
1169 1164
1170our $VERSION = '5.271'; 1165our $VERSION = '5.29';
1171our $MODEL; 1166our $MODEL;
1172 1167
1173our $AUTOLOAD; 1168our $AUTOLOAD;
1174our @ISA; 1169our @ISA;
1175 1170
1213 [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles 1208 [Tk:: => AnyEvent::Impl::Tk::], # crashes with many handles
1214 [Qt:: => AnyEvent::Impl::Qt::], # requires special main program 1209 [Qt:: => AnyEvent::Impl::Qt::], # requires special main program
1215 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza 1210 [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza
1216 [Wx:: => AnyEvent::Impl::POE::], 1211 [Wx:: => AnyEvent::Impl::POE::],
1217 [Prima:: => AnyEvent::Impl::POE::], 1212 [Prima:: => AnyEvent::Impl::POE::],
1218 # IO::Async is just too broken - we would need workarounds for its
1219 # byzantine signal and broken child handling, among others.
1220 # IO::Async is rather hard to detect, as it doesn't have any
1221 # obvious default class.
1222 [IO::Async:: => AnyEvent::Impl::IOAsync::], # requires special main program
1223 [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::], # requires special main program 1213 [IO::Async::Loop:: => AnyEvent::Impl::IOAsync::],
1224 [IO::Async::Notifier:: => AnyEvent::Impl::IOAsync::], # requires special main program
1225 [AnyEvent::Impl::IOAsync:: => AnyEvent::Impl::IOAsync::], # requires special main program
1226); 1214);
1227 1215
1228our %method = map +($_ => 1), 1216our %method = map +($_ => 1),
1229 qw(io timer time now now_update signal child idle condvar one_event DESTROY); 1217 qw(io timer time now now_update signal child idle condvar one_event DESTROY);
1230 1218
1289 last; 1277 last;
1290 } 1278 }
1291 } 1279 }
1292 1280
1293 $MODEL 1281 $MODEL
1294 or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: EV, Event or Glib.\n"; 1282 or die "AnyEvent: backend autodetection failed - did you properly install AnyEvent?\n";
1295 } 1283 }
1296 } 1284 }
1297 1285
1298 @models = (); # free probe data 1286 @models = (); # free probe data
1299 1287
1300 push @{"$MODEL\::ISA"}, "AnyEvent::Base"; 1288 push @{"$MODEL\::ISA"}, "AnyEvent::Base";
1301 unshift @ISA, $MODEL; 1289 unshift @ISA, $MODEL;
1302 1290
1303 # now nuke some methods that are overriden by the backend. 1291 # now nuke some methods that are overridden by the backend.
1304 # SUPER is not allowed. 1292 # SUPER is not allowed.
1305 for (qw(time signal child idle)) { 1293 for (qw(time signal child idle)) {
1306 undef &{"AnyEvent::Base::$_"} 1294 undef &{"AnyEvent::Base::$_"}
1307 if defined &{"$MODEL\::$_"}; 1295 if defined &{"$MODEL\::$_"};
1308 } 1296 }
1309 1297
1310 require AnyEvent::Strict if $ENV{PERL_ANYEVENT_STRICT}; 1298 if ($ENV{PERL_ANYEVENT_STRICT}) {
1299 eval { require AnyEvent::Strict };
1300 warn "AnyEvent: cannot load AnyEvent::Strict: $@"
1301 if $@ && $VERBOSE;
1302 }
1311 1303
1312 (shift @post_detect)->() while @post_detect; 1304 (shift @post_detect)->() while @post_detect;
1313 1305
1314 *post_detect = sub(&) { 1306 *post_detect = sub(&) {
1315 shift->(); 1307 shift->();
1622# default implementation for ->child 1614# default implementation for ->child
1623 1615
1624our %PID_CB; 1616our %PID_CB;
1625our $CHLD_W; 1617our $CHLD_W;
1626our $CHLD_DELAY_W; 1618our $CHLD_DELAY_W;
1627our $WNOHANG;
1628 1619
1629# used by many Impl's 1620# used by many Impl's
1630sub _emit_childstatus($$) { 1621sub _emit_childstatus($$) {
1631 my (undef, $rpid, $rstatus) = @_; 1622 my (undef, $rpid, $rstatus) = @_;
1632 1623
1639 eval q{ # poor man's autoloading {} 1630 eval q{ # poor man's autoloading {}
1640 *_sigchld = sub { 1631 *_sigchld = sub {
1641 my $pid; 1632 my $pid;
1642 1633
1643 AnyEvent->_emit_childstatus ($pid, $?) 1634 AnyEvent->_emit_childstatus ($pid, $?)
1644 while ($pid = waitpid -1, $WNOHANG) > 0; 1635 while ($pid = waitpid -1, WNOHANG) > 0;
1645 }; 1636 };
1646 1637
1647 *child = sub { 1638 *child = sub {
1648 my (undef, %arg) = @_; 1639 my (undef, %arg) = @_;
1649 1640
1650 defined (my $pid = $arg{pid} + 0) 1641 defined (my $pid = $arg{pid} + 0)
1651 or Carp::croak "required option 'pid' is missing"; 1642 or Carp::croak "required option 'pid' is missing";
1652 1643
1653 $PID_CB{$pid}{$arg{cb}} = $arg{cb}; 1644 $PID_CB{$pid}{$arg{cb}} = $arg{cb};
1654
1655 # WNOHANG is almost cetrainly 1 everywhere
1656 $WNOHANG ||= $^O =~ /^(?:openbsd|netbsd|linux|freebsd|cygwin|MSWin32)$/
1657 ? 1
1658 : eval { local $SIG{__DIE__}; require POSIX; &POSIX::WNOHANG } || 1;
1659 1645
1660 unless ($CHLD_W) { 1646 unless ($CHLD_W) {
1661 $CHLD_W = AE::signal CHLD => \&_sigchld; 1647 $CHLD_W = AE::signal CHLD => \&_sigchld;
1662 # child could be a zombie already, so make at least one round 1648 # child could be a zombie already, so make at least one round
1663 &_sigchld; 1649 &_sigchld;
1724} 1710}
1725 1711
1726package AnyEvent::CondVar; 1712package AnyEvent::CondVar;
1727 1713
1728our @ISA = AnyEvent::CondVar::Base::; 1714our @ISA = AnyEvent::CondVar::Base::;
1715
1716# only to be used for subclassing
1717sub new {
1718 my $class = shift;
1719 bless AnyEvent->condvar (@_), $class
1720}
1729 1721
1730package AnyEvent::CondVar::Base; 1722package AnyEvent::CondVar::Base;
1731 1723
1732#use overload 1724#use overload
1733# '&{}' => sub { my $self = shift; sub { $self->send (@_) } }, 1725# '&{}' => sub { my $self = shift; sub { $self->send (@_) } },
2652pronounced). 2644pronounced).
2653 2645
2654 2646
2655=head1 SEE ALSO 2647=head1 SEE ALSO
2656 2648
2649Tutorial/Introduction: L<AnyEvent::Intro>.
2650
2651FAQ: L<AnyEvent::FAQ>.
2652
2657Utility functions: L<AnyEvent::Util>. 2653Utility functions: L<AnyEvent::Util>.
2658 2654
2659Event modules: L<EV>, L<EV::Glib>, L<Glib::EV>, L<Event>, L<Glib::Event>, 2655Event modules: L<EV>, L<EV::Glib>, L<Glib::EV>, L<Event>, L<Glib::Event>,
2660L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. 2656L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>.
2661 2657
2667Non-blocking file handles, sockets, TCP clients and 2663Non-blocking file handles, sockets, TCP clients and
2668servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>. 2664servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>.
2669 2665
2670Asynchronous DNS: L<AnyEvent::DNS>. 2666Asynchronous DNS: L<AnyEvent::DNS>.
2671 2667
2672Coroutine support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, 2668Thread support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>.
2673L<Coro::Event>,
2674 2669
2675Nontrivial usage examples: L<AnyEvent::GPSD>, L<AnyEvent::XMPP>, 2670Nontrivial usage examples: L<AnyEvent::GPSD>, L<AnyEvent::IRC>,
2676L<AnyEvent::HTTP>. 2671L<AnyEvent::HTTP>.
2677 2672
2678 2673
2679=head1 AUTHOR 2674=head1 AUTHOR
2680 2675

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines