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.15 by root, Mon Oct 30 20:55:05 2006 UTC vs.
Revision 1.18 by root, Sun Dec 10 21:33:33 2006 UTC

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
168Contains C<undef> until the first watcher is being created. Then it
169contains the event model that is being used, which is the name of the
170Perl class implementing the model. This class is usually one of the
171C<AnyEvent::Impl:xxx> modules, but can be any other class in the case
172AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>).
173
174The 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
164As a module author, you should "use AnyEvent" and call AnyEvent methods 186As a module author, you should "use AnyEvent" and call AnyEvent methods
165freely, but you should not load a specific event module or rely on it. 187freely, but you should not load a specific event module or rely on it.
166 188
195 217
196no warnings; 218no warnings;
197use strict 'vars'; 219use strict 'vars';
198use Carp; 220use Carp;
199 221
200our $VERSION = '2.0'; 222our $VERSION = '2.1';
201our $MODEL; 223our $MODEL;
202 224
203our $AUTOLOAD; 225our $AUTOLOAD;
204our @ISA; 226our @ISA;
205 227
206our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; 228our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1;
207 229
208our @REGISTRY; 230our @REGISTRY;
209 231
210my @models = ( 232my @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
218our %method = map +($_ => 1), qw(io timer condvar broadcast wait DESTROY); 240our %method = map +($_ => 1), qw(io timer condvar broadcast wait DESTROY);
219 241
220sub AUTOLOAD { 242sub 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
264If you need to support another event library which isn't directly 286If you need to support another event library which isn't directly

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines