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.7 by root, Fri Dec 30 01:28:31 2005 UTC vs.
Revision 1.13 by root, Thu Jul 20 08:26:00 2006 UTC

44C<< ->wait >> for it. See the examples below. 44C<< ->wait >> for it. See the examples below.
45 45
46=head1 DESCRIPTION 46=head1 DESCRIPTION
47 47
48L<AnyEvent> provides an identical interface to multiple event loops. This 48L<AnyEvent> provides an identical interface to multiple event loops. This
49allows module authors to utilizy an event loop without forcing module 49allows module authors to utilise an event loop without forcing module
50users to use the same event loop (as only a single event loop can coexist 50users to use the same event loop (as only a single event loop can coexist
51peacefully at any one time). 51peacefully at any one time).
52 52
53The interface itself is vaguely similar but not identical to the Event 53The interface itself is vaguely similar but not identical to the Event
54module. 54module.
68 68
69no warnings; 69no warnings;
70use strict 'vars'; 70use strict 'vars';
71use Carp; 71use Carp;
72 72
73our $VERSION = '0.4'; 73our $VERSION = '1.02';
74our $MODEL; 74our $MODEL;
75 75
76our $AUTOLOAD; 76our $AUTOLOAD;
77our @ISA; 77our @ISA;
78 78
79our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; 79our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1;
80 80
81our @REGISTRY;
82
81my @models = ( 83my @models = (
82 [Coro => Coro::Event::], 84 [Coro::Event:: => AnyEvent::Impl::Coro::],
83 [Event => Event::], 85 [Event:: => AnyEvent::Impl::Event::],
84 [Glib => Glib::], 86 [Glib:: => AnyEvent::Impl::Glib::],
85 [Tk => Tk::], 87 [Tk:: => AnyEvent::Impl::Tk::],
86); 88);
87 89
88our %method = map +($_ => 1), qw(io timer condvar broadcast wait cancel DESTROY); 90our %method = map +($_ => 1), qw(io timer condvar broadcast wait cancel DESTROY);
89 91
90sub AUTOLOAD { 92sub AUTOLOAD {
93 $method{$AUTOLOAD} 95 $method{$AUTOLOAD}
94 or croak "$AUTOLOAD: not a valid method for AnyEvent objects"; 96 or croak "$AUTOLOAD: not a valid method for AnyEvent objects";
95 97
96 unless ($MODEL) { 98 unless ($MODEL) {
97 # check for already loaded models 99 # check for already loaded models
98 for (@models) { 100 for (@REGISTRY, @models) {
99 my ($model, $package) = @$_; 101 my ($package, $model) = @$_;
100 if (${"$package\::VERSION"} > 0) { 102 if (${"$package\::VERSION"} > 0) {
101 eval "require AnyEvent::Impl::$model"; 103 if (eval "require $model") {
104 $MODEL = $model;
102 warn "AnyEvent: found model '$model', using it.\n" if $MODEL && $verbose > 1; 105 warn "AnyEvent: found model '$model', using it.\n" if $verbose > 1;
103 last if $MODEL; 106 last;
107 }
104 } 108 }
105 } 109 }
106 110
107 unless ($MODEL) { 111 unless ($MODEL) {
108 # try to load a model 112 # try to load a model
109 113
110 for (@models) { 114 for (@REGISTRY, @models) {
111 my ($model, $package) = @$_; 115 my ($package, $model) = @$_;
112 eval "require AnyEvent::Impl::$model"; 116 if (eval "require $model") {
117 $MODEL = $model;
113 warn "AnyEvent: autprobed and loaded model '$model', using it.\n" if $MODEL && $verbose > 1; 118 warn "AnyEvent: autoprobed and loaded model '$model', using it.\n" if $verbose > 1;
114 last if $MODEL; 119 last;
120 }
115 } 121 }
116 122
117 $MODEL 123 $MODEL
118 or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: Coro, Event, Glib or Tk."; 124 or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: Coro, Event, Glib or Tk.";
119 } 125 }
124 my $class = shift; 130 my $class = shift;
125 $class->$AUTOLOAD (@_); 131 $class->$AUTOLOAD (@_);
126} 132}
127 133
128=back 134=back
135
136=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE
137
138If you need to support another event library which isn't directly
139supported by AnyEvent, you can supply your own interface to it by
140pushing, before the first watcher gets created, the package name of
141the event module and the package name of the interface to use onto
142C<@AnyEvent::REGISTRY>. You can do that before and even without loading
143AnyEvent.
144
145Example:
146
147 push @AnyEvent::REGISTRY, [urxvt => urxvt::anyevent::];
148
149This tells AnyEvent to (literally) use the C<urxvt::anyevent::>
150package/class when it finds the C<urxvt> package/module is loaded. When
151AnyEvent is loaded and asked to find a suitable event model, it will
152first check for the presence of urxvt.
153
154The class should prove implementations for all watcher types (see
155L<AnyEvent::Impl::Event> (source code), L<AnyEvent::Impl::Glib>
156(Source code) and so on for actual examples, use C<perldoc -m
157AnyEvent::Impl::Glib> to see the sources).
158
159The above isn't fictitious, the I<rxvt-unicode> (a.k.a. urxvt)
160uses the above line as-is. An interface isn't included in AnyEvent
161because it doesn't make sense outside the embedded interpreter inside
162I<rxvt-unicode>, and it is updated and maintained as part of the
163I<rxvt-unicode> distribution.
164
165I<rxvt-unicode> also cheats a bit by not providing blocking access to
166condition variables: code blocking while waiting for a condition will
167C<die>. This still works with most modules/usages, and blocking calls must
168not be in an interactive appliation, so it makes sense.
129 169
130=head1 ENVIRONMENT VARIABLES 170=head1 ENVIRONMENT VARIABLES
131 171
132The following environment variables are used by this module: 172The following environment variables are used by this module:
133 173

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines