--- cvsroot/Net-FCP/FCP.pm 2003/09/13 06:39:15 1.18 +++ cvsroot/Net-FCP/FCP.pm 2003/09/15 00:05:32 1.20 @@ -37,6 +37,9 @@ You should specify the event module to use only in the main program. +If no event model has been specified, FCP tries to autodetect it on first +use (e.g. first transaction), in this order: Coro, Event, Glib, Tk. + =head2 FREENET BASICS Ok, this section will not explain any freenet basics to you, just some @@ -71,12 +74,11 @@ use Carp; -$VERSION = 0.07; +$VERSION = 0.08; no warnings; our $EVENT = Net::FCP::Event::Auto::; -$EVENT = Net::FCP::Event::Event;#d# sub import { shift; @@ -84,9 +86,9 @@ for (@_) { if (/^event=(\w+)$/) { $EVENT = "Net::FCP::Event::$1"; + eval "require $EVENT"; } } - eval "require $EVENT"; die $@ if $@; } @@ -775,7 +777,7 @@ $self->{data} .= $chunk; - $self->progress ("data", { chunk => length $chunk, total => length $self->{data}, end => $self->{datalength} }); + $self->progress ("data", { chunk => length $chunk, received => length $self->{data}, total => $self->{datalength} }); if ($self->{datalength} == length $self->{data}) { my $data = delete $self->{data}; @@ -891,5 +893,37 @@ =cut +package Net::FCP::Event::Auto; + +my @models = ( + [Coro => Coro::Event:: ], + [Event => Event::], + [Glib => Glib:: ], + [Tk => Tk::], +); + +sub AUTOLOAD { + $AUTOLOAD =~ s/.*://; + + for (@models) { + my ($model, $package) = @$_; + if (defined ${"$package\::VERSION"}) { + $EVENT = "Net::FCP::Event::$model"; + eval "require $EVENT"; die if $@; + goto &{"$EVENT\::$AUTOLOAD"}; + } + } + + for (@models) { + my ($model, $package) = @$_; + $EVENT = "Net::FCP::Event::$model"; + if (eval "require $EVENT") { + goto &{"$EVENT\::$AUTOLOAD"}; + } + } + + die "No event module selected for Net::FCP and autodetect failed. Install any of these: Coro, Event, Glib or Tk."; +} + 1;