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.8 by root, Sun Jan 8 04:20:05 2006 UTC

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.0';
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 watch 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::> module
150when it finds the C<urxvt> module is loaded. When AnyEvent is loaded and
151requested to find a suitable event model, it will first check for the
152urxvt module.
153
154The above isn't fictitious, the I<rxvt-unicode> (a.k.a. urxvt) uses
155the above line exactly. An interface isn't included in AnyEvent
156because it doesn't make sense outside the embedded interpreter inside
157I<rxvt-unicode>, and it is updated and maintained as part of the
158I<rxvt-unicode> distribution.
129 159
130=head1 ENVIRONMENT VARIABLES 160=head1 ENVIRONMENT VARIABLES
131 161
132The following environment variables are used by this module: 162The following environment variables are used by this module:
133 163

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines