… | |
… | |
48 | isn't itself. What's worse, all the potential users of your module are |
48 | isn't itself. What's worse, all the potential users of your module are |
49 | I<also> forced to use the same event loop you use. |
49 | I<also> forced to use the same event loop you use. |
50 | |
50 | |
51 | AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works |
51 | AnyEvent is different: AnyEvent + POE works fine. AnyEvent + Glib works |
52 | fine. AnyEvent + Tk works fine etc. etc. but none of these work together |
52 | fine. AnyEvent + Tk works fine etc. etc. but none of these work together |
53 | with the rest: POE + IO::Async? no go. Tk + Event? no go. Again: if |
53 | with the rest: POE + IO::Async? No go. Tk + Event? No go. Again: if |
54 | your module uses one of those, every user of your module has to use it, |
54 | your module uses one of those, every user of your module has to use it, |
55 | too. But if your module uses AnyEvent, it works transparently with all |
55 | too. But if your module uses AnyEvent, it works transparently with all |
56 | event models it supports (including stuff like POE and IO::Async, as long |
56 | event models it supports (including stuff like POE and IO::Async, as long |
57 | as those use one of the supported event loops. It is trivial to add new |
57 | as those use one of the supported event loops. It is trivial to add new |
58 | event loops to AnyEvent, too, so it is future-proof). |
58 | event loops to AnyEvent, too, so it is future-proof). |
… | |
… | |
62 | modules, you get an enormous amount of code and strict rules you have to |
62 | modules, you get an enormous amount of code and strict rules you have to |
63 | follow. AnyEvent, on the other hand, is lean and up to the point, by only |
63 | follow. AnyEvent, on the other hand, is lean and up to the point, by only |
64 | offering the functionality that is necessary, in as thin as a wrapper as |
64 | offering the functionality that is necessary, in as thin as a wrapper as |
65 | technically possible. |
65 | technically possible. |
66 | |
66 | |
|
|
67 | Of course, AnyEvent comes with a big (and fully optional!) toolbox |
|
|
68 | of useful functionality, such as an asynchronous DNS resolver, 100% |
|
|
69 | non-blocking connects (even with TLS/SSL, IPv6 and on broken platforms |
|
|
70 | such as Windows) and lots of real-world knowledge and workarounds for |
|
|
71 | platform bugs and differences. |
|
|
72 | |
67 | Of course, if you want lots of policy (this can arguably be somewhat |
73 | Now, if you I<do want> lots of policy (this can arguably be somewhat |
68 | useful) and you want to force your users to use the one and only event |
74 | useful) and you want to force your users to use the one and only event |
69 | model, you should I<not> use this module. |
75 | model, you should I<not> use this module. |
70 | |
76 | |
71 | =head1 DESCRIPTION |
77 | =head1 DESCRIPTION |
72 | |
78 | |
… | |
… | |
102 | starts using it, all bets are off. Maybe you should tell their authors to |
108 | starts using it, all bets are off. Maybe you should tell their authors to |
103 | use AnyEvent so their modules work together with others seamlessly... |
109 | use AnyEvent so their modules work together with others seamlessly... |
104 | |
110 | |
105 | The pure-perl implementation of AnyEvent is called |
111 | The pure-perl implementation of AnyEvent is called |
106 | C<AnyEvent::Impl::Perl>. Like other event modules you can load it |
112 | C<AnyEvent::Impl::Perl>. Like other event modules you can load it |
107 | explicitly. |
113 | explicitly and enjoy the high availability of that event loop :) |
108 | |
114 | |
109 | =head1 WATCHERS |
115 | =head1 WATCHERS |
110 | |
116 | |
111 | AnyEvent has the central concept of a I<watcher>, which is an object that |
117 | AnyEvent has the central concept of a I<watcher>, which is an object that |
112 | stores relevant data for each kind of event you are waiting for, such as |
118 | stores relevant data for each kind of event you are waiting for, such as |
… | |
… | |
731 | no warnings; |
737 | no warnings; |
732 | use strict; |
738 | use strict; |
733 | |
739 | |
734 | use Carp; |
740 | use Carp; |
735 | |
741 | |
736 | our $VERSION = '4.03'; |
742 | our $VERSION = '4.05'; |
737 | our $MODEL; |
743 | our $MODEL; |
738 | |
744 | |
739 | our $AUTOLOAD; |
745 | our $AUTOLOAD; |
740 | our @ISA; |
746 | our @ISA; |
741 | |
747 | |
… | |
… | |
755 | { |
761 | { |
756 | my $idx; |
762 | my $idx; |
757 | $PROTOCOL{$_} = ++$idx |
763 | $PROTOCOL{$_} = ++$idx |
758 | for reverse split /\s*,\s*/, |
764 | for reverse split /\s*,\s*/, |
759 | $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; |
765 | $ENV{PERL_ANYEVENT_PROTOCOLS} || "ipv4,ipv6"; |
760 | } |
|
|
761 | |
|
|
762 | sub import { |
|
|
763 | shift; |
|
|
764 | return unless @_; |
|
|
765 | |
|
|
766 | my $pkg = caller; |
|
|
767 | |
|
|
768 | no strict 'refs'; |
|
|
769 | |
|
|
770 | for (@_) { |
|
|
771 | *{"$pkg\::WIN32"} = *WIN32 if $_ eq "WIN32"; |
|
|
772 | } |
|
|
773 | } |
766 | } |
774 | |
767 | |
775 | my @models = ( |
768 | my @models = ( |
776 | [EV:: => AnyEvent::Impl::EV::], |
769 | [EV:: => AnyEvent::Impl::EV::], |
777 | [Event:: => AnyEvent::Impl::Event::], |
770 | [Event:: => AnyEvent::Impl::Event::], |
… | |
… | |
1136 | default. |
1129 | default. |
1137 | |
1130 | |
1138 | Setting this variable to C<1> will cause L<AnyEvent::DNS> to announce |
1131 | Setting this variable to C<1> will cause L<AnyEvent::DNS> to announce |
1139 | EDNS0 in its DNS requests. |
1132 | EDNS0 in its DNS requests. |
1140 | |
1133 | |
|
|
1134 | =item C<PERL_ANYEVENT_MAX_FORKS> |
|
|
1135 | |
|
|
1136 | The maximum number of child processes that C<AnyEvent::Util::fork_call> |
|
|
1137 | will create in parallel. |
|
|
1138 | |
1141 | =back |
1139 | =back |
1142 | |
1140 | |
1143 | =head1 EXAMPLE PROGRAM |
1141 | =head1 EXAMPLE PROGRAM |
1144 | |
1142 | |
1145 | The following program uses an I/O watcher to read data from STDIN, a timer |
1143 | The following program uses an I/O watcher to read data from STDIN, a timer |