… | |
… | |
157 | |
157 | |
158 | $result_ready->wait; |
158 | $result_ready->wait; |
159 | |
159 | |
160 | =back |
160 | =back |
161 | |
161 | |
|
|
162 | =head1 GLOBALS |
|
|
163 | |
|
|
164 | =over 4 |
|
|
165 | |
|
|
166 | =item $AnyEvent::MODEL |
|
|
167 | |
|
|
168 | Contains C<undef> until the first watcher is being created. Then it |
|
|
169 | contains the event model that is being used, which is the name of the |
|
|
170 | Perl class implementing the model. This class is usually one of the |
|
|
171 | C<AnyEvent::Impl:xxx> modules, but can be any other class in the case |
|
|
172 | AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>). |
|
|
173 | |
|
|
174 | The known classes so far are: |
|
|
175 | |
|
|
176 | AnyEvent::Impl::Coro based on Coro::Event, best choise. |
|
|
177 | AnyEvent::Impl::Event based on Event, also best choice :) |
|
|
178 | AnyEvent::Impl::Glib based on Glib, second-best choice. |
|
|
179 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
|
|
180 | AnyEvent::Impl::Perl pure-perl implementation, inefficient. |
|
|
181 | |
|
|
182 | =back |
|
|
183 | |
162 | =head1 WHAT TO DO IN A MODULE |
184 | =head1 WHAT TO DO IN A MODULE |
163 | |
185 | |
164 | As a module author, you should "use AnyEvent" and call AnyEvent methods |
186 | As a module author, you should "use AnyEvent" and call AnyEvent methods |
165 | freely, but you should not load a specific event module or rely on it. |
187 | freely, but you should not load a specific event module or rely on it. |
166 | |
188 | |
… | |
… | |
195 | |
217 | |
196 | no warnings; |
218 | no warnings; |
197 | use strict 'vars'; |
219 | use strict 'vars'; |
198 | use Carp; |
220 | use Carp; |
199 | |
221 | |
200 | our $VERSION = '2.0'; |
222 | our $VERSION = '2.1'; |
201 | our $MODEL; |
223 | our $MODEL; |
202 | |
224 | |
203 | our $AUTOLOAD; |
225 | our $AUTOLOAD; |
204 | our @ISA; |
226 | our @ISA; |
205 | |
227 | |
206 | our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; |
228 | our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; |
207 | |
229 | |
208 | our @REGISTRY; |
230 | our @REGISTRY; |
209 | |
231 | |
210 | my @models = ( |
232 | my @models = ( |
211 | [Coro::Event:: => AnyEvent::Impl::Coro::], |
233 | [Coro::Event:: => AnyEvent::Impl::Coro::], |
212 | [Event:: => AnyEvent::Impl::Event::], |
234 | [Event:: => AnyEvent::Impl::Event::], |
213 | [Glib:: => AnyEvent::Impl::Glib::], |
235 | [Glib:: => AnyEvent::Impl::Glib::], |
214 | [Tk:: => AnyEvent::Impl::Tk::], |
236 | [Tk:: => AnyEvent::Impl::Tk::], |
215 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
237 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
216 | ); |
238 | ); |
217 | |
239 | |
218 | our %method = map +($_ => 1), qw(io timer condvar broadcast wait DESTROY); |
240 | our %method = map +($_ => 1), qw(io timer condvar broadcast wait DESTROY); |
219 | |
241 | |
220 | sub AUTOLOAD { |
242 | sub AUTOLOAD { |
221 | $AUTOLOAD =~ s/.*://; |
243 | (my $func = $AUTOLOAD) =~ s/.*://; |
222 | |
244 | |
223 | $method{$AUTOLOAD} |
245 | $method{$func} |
224 | or croak "$AUTOLOAD: not a valid method for AnyEvent objects"; |
246 | or croak "$func: not a valid method for AnyEvent objects"; |
225 | |
247 | |
226 | unless ($MODEL) { |
248 | unless ($MODEL) { |
227 | # check for already loaded models |
249 | # check for already loaded models |
228 | for (@REGISTRY, @models) { |
250 | for (@REGISTRY, @models) { |
229 | my ($package, $model) = @$_; |
251 | my ($package, $model) = @$_; |
… | |
… | |
254 | } |
276 | } |
255 | |
277 | |
256 | @ISA = $MODEL; |
278 | @ISA = $MODEL; |
257 | |
279 | |
258 | my $class = shift; |
280 | my $class = shift; |
259 | $class->$AUTOLOAD (@_); |
281 | $class->$func (@_); |
260 | } |
282 | } |
261 | |
283 | |
262 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
284 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
263 | |
285 | |
264 | If you need to support another event library which isn't directly |
286 | If you need to support another event library which isn't directly |