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.148 by root, Sat May 31 00:40:16 2008 UTC vs.
Revision 1.159 by root, Fri Jun 6 16:19:19 2008 UTC

1=head1 => NAME 1=head1 NAME
2 2
3AnyEvent - provide framework for multiple event loops 3AnyEvent - provide framework for multiple event loops
4 4
5EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops 5EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event loops
6 6
138Many watchers either are used with "recursion" (repeating timers for 138Many watchers either are used with "recursion" (repeating timers for
139example), or need to refer to their watcher object in other ways. 139example), or need to refer to their watcher object in other ways.
140 140
141An any way to achieve that is this pattern: 141An any way to achieve that is this pattern:
142 142
143 my $w; $w = AnyEvent->type (arg => value ..., cb => sub { 143 my $w; $w = AnyEvent->type (arg => value ..., cb => sub {
144 # you can use $w here, for example to undef it 144 # you can use $w here, for example to undef it
145 undef $w; 145 undef $w;
146 }); 146 });
147 147
148Note that C<my $w; $w => combination. This is necessary because in Perl, 148Note that C<my $w; $w => combination. This is necessary because in Perl,
149my variables are only visible after the statement in which they are 149my variables are only visible after the statement in which they are
150declared. 150declared.
151 151
352AnyEvent program, you I<have> to create at least one watcher before you 352AnyEvent program, you I<have> to create at least one watcher before you
353C<fork> the child (alternatively, you can call C<AnyEvent::detect>). 353C<fork> the child (alternatively, you can call C<AnyEvent::detect>).
354 354
355Example: fork a process and wait for it 355Example: fork a process and wait for it
356 356
357 my $done = AnyEvent->condvar; 357 my $done = AnyEvent->condvar;
358 358
359 my $pid = fork or exit 5; 359 my $pid = fork or exit 5;
360 360
361 my $w = AnyEvent->child ( 361 my $w = AnyEvent->child (
362 pid => $pid, 362 pid => $pid,
363 cb => sub { 363 cb => sub {
364 my ($pid, $status) = @_; 364 my ($pid, $status) = @_;
365 warn "pid $pid exited with status $status"; 365 warn "pid $pid exited with status $status";
366 $done->send; 366 $done->send;
367 }, 367 },
368 ); 368 );
369 369
370 # do something else, then wait for process exit 370 # do something else, then wait for process exit
371 $done->recv; 371 $done->recv;
372 372
373=head2 CONDITION VARIABLES 373=head2 CONDITION VARIABLES
374 374
375If you are familiar with some event loops you will know that all of them 375If you are familiar with some event loops you will know that all of them
376require you to run some blocking "loop", "run" or similar function that 376require you to run some blocking "loop", "run" or similar function that
597 597
598This is a mutator function that returns the callback set and optionally 598This is a mutator function that returns the callback set and optionally
599replaces it before doing so. 599replaces it before doing so.
600 600
601The callback will be called when the condition becomes "true", i.e. when 601The callback will be called when the condition becomes "true", i.e. when
602C<send> or C<croak> are called. Calling C<recv> inside the callback 602C<send> or C<croak> are called, with the only argument being the condition
603or at any later time is guaranteed not to block. 603variable itself. Calling C<recv> inside the callback or at any later time
604is guaranteed not to block.
604 605
605=back 606=back
606 607
607=head1 GLOBAL VARIABLES AND FUNCTIONS 608=head1 GLOBAL VARIABLES AND FUNCTIONS
608 609
751 752
752=item L<AnyEvent::DNS> 753=item L<AnyEvent::DNS>
753 754
754Provides rich asynchronous DNS resolver capabilities. 755Provides rich asynchronous DNS resolver capabilities.
755 756
757=item L<AnyEvent::HTTP>
758
759A simple-to-use HTTP library that is capable of making a lot of concurrent
760HTTP requests.
761
756=item L<AnyEvent::HTTPD> 762=item L<AnyEvent::HTTPD>
757 763
758Provides a simple web application server framework. 764Provides a simple web application server framework.
759 765
760=item L<AnyEvent::FastPing> 766=item L<AnyEvent::FastPing>
761 767
762The fastest ping in the west. 768The fastest ping in the west.
769
770=item L<AnyEvent::DBI>
771
772Executes DBI requests asynchronously in a proxy process.
763 773
764=item L<Net::IRC3> 774=item L<Net::IRC3>
765 775
766AnyEvent based IRC client module family. 776AnyEvent based IRC client module family.
767 777
806no warnings; 816no warnings;
807use strict; 817use strict;
808 818
809use Carp; 819use Carp;
810 820
811our $VERSION = 4.11; 821our $VERSION = 4.151;
812our $MODEL; 822our $MODEL;
813 823
814our $AUTOLOAD; 824our $AUTOLOAD;
815our @ISA; 825our @ISA;
816 826
1172This functionality might change in future versions. 1182This functionality might change in future versions.
1173 1183
1174For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you 1184For example, to force the pure perl model (L<AnyEvent::Impl::Perl>) you
1175could start your program like this: 1185could start your program like this:
1176 1186
1177 PERL_ANYEVENT_MODEL=Perl perl ... 1187 PERL_ANYEVENT_MODEL=Perl perl ...
1178 1188
1179=item C<PERL_ANYEVENT_PROTOCOLS> 1189=item C<PERL_ANYEVENT_PROTOCOLS>
1180 1190
1181Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences 1191Used by both L<AnyEvent::DNS> and L<AnyEvent::Socket> to determine preferences
1182for IPv4 or IPv6. The default is unspecified (and might change, or be the result 1192for IPv4 or IPv6. The default is unspecified (and might change, or be the result
1657specified in the variable. 1667specified in the variable.
1658 1668
1659You can make AnyEvent completely ignore this variable by deleting it 1669You can make AnyEvent completely ignore this variable by deleting it
1660before the first watcher gets created, e.g. with a C<BEGIN> block: 1670before the first watcher gets created, e.g. with a C<BEGIN> block:
1661 1671
1662 BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } 1672 BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} }
1663 1673
1664 use AnyEvent; 1674 use AnyEvent;
1665 1675
1666Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can 1676Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can
1667be used to probe what backend is used and gain other information (which is 1677be used to probe what backend is used and gain other information (which is
1668probably even less useful to an attacker than PERL_ANYEVENT_MODEL). 1678probably even less useful to an attacker than PERL_ANYEVENT_MODEL).
1679
1680
1681=head1 BUGS
1682
1683Perl 5.8 has numerous memleaks that sometimes hit this module and are hard
1684to work around. If you suffer from memleaks, first upgrade to Perl 5.10
1685and check wether the leaks still show up. (Perl 5.10.0 has other annoying
1686mamleaks, such as leaking on C<map> and C<grep> but it is usually not as
1687pronounced).
1669 1688
1670 1689
1671=head1 SEE ALSO 1690=head1 SEE ALSO
1672 1691
1673Utility functions: L<AnyEvent::Util>. 1692Utility functions: L<AnyEvent::Util>.
1690Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. 1709Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>.
1691 1710
1692 1711
1693=head1 AUTHOR 1712=head1 AUTHOR
1694 1713
1695 Marc Lehmann <schmorp@schmorp.de> 1714 Marc Lehmann <schmorp@schmorp.de>
1696 http://home.schmorp.de/ 1715 http://home.schmorp.de/
1697 1716
1698=cut 1717=cut
1699 1718
17001 17191
1701 1720

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines