ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-FCP/FCP.pm
(Generate patch)

Comparing cvsroot/Net-FCP/FCP.pm (file contents):
Revision 1.18 by root, Sat Sep 13 06:39:15 2003 UTC vs.
Revision 1.20 by root, Mon Sep 15 00:05:32 2003 UTC

34 34
35The import tag to use is named C<event=xyz>, e.g. C<event=Event>, 35The import tag to use is named C<event=xyz>, e.g. C<event=Event>,
36C<event=Glib> etc. 36C<event=Glib> etc.
37 37
38You should specify the event module to use only in the main program. 38You should specify the event module to use only in the main program.
39
40If no event model has been specified, FCP tries to autodetect it on first
41use (e.g. first transaction), in this order: Coro, Event, Glib, Tk.
39 42
40=head2 FREENET BASICS 43=head2 FREENET BASICS
41 44
42Ok, this section will not explain any freenet basics to you, just some 45Ok, this section will not explain any freenet basics to you, just some
43problems I found that you might want to avoid: 46problems I found that you might want to avoid:
69 72
70package Net::FCP; 73package Net::FCP;
71 74
72use Carp; 75use Carp;
73 76
74$VERSION = 0.07; 77$VERSION = 0.08;
75 78
76no warnings; 79no warnings;
77 80
78our $EVENT = Net::FCP::Event::Auto::; 81our $EVENT = Net::FCP::Event::Auto::;
79$EVENT = Net::FCP::Event::Event;#d#
80 82
81sub import { 83sub import {
82 shift; 84 shift;
83 85
84 for (@_) { 86 for (@_) {
85 if (/^event=(\w+)$/) { 87 if (/^event=(\w+)$/) {
86 $EVENT = "Net::FCP::Event::$1"; 88 $EVENT = "Net::FCP::Event::$1";
89 eval "require $EVENT";
87 } 90 }
88 } 91 }
89 eval "require $EVENT";
90 die $@ if $@; 92 die $@ if $@;
91} 93}
92 94
93sub touc($) { 95sub touc($) {
94 local $_ = shift; 96 local $_ = shift;
773sub rcv_data { 775sub rcv_data {
774 my ($self, $chunk) = @_; 776 my ($self, $chunk) = @_;
775 777
776 $self->{data} .= $chunk; 778 $self->{data} .= $chunk;
777 779
778 $self->progress ("data", { chunk => length $chunk, total => length $self->{data}, end => $self->{datalength} }); 780 $self->progress ("data", { chunk => length $chunk, received => length $self->{data}, total => $self->{datalength} });
779 781
780 if ($self->{datalength} == length $self->{data}) { 782 if ($self->{datalength} == length $self->{data}) {
781 my $data = delete $self->{data}; 783 my $data = delete $self->{data};
782 my $meta = Net::FCP::parse_metadata substr $data, 0, $self->{metalength}, ""; 784 my $meta = Net::FCP::parse_metadata substr $data, 0, $self->{metalength}, "";
783 785
889 Marc Lehmann <pcg@goof.com> 891 Marc Lehmann <pcg@goof.com>
890 http://www.goof.com/pcg/marc/ 892 http://www.goof.com/pcg/marc/
891 893
892=cut 894=cut
893 895
896package Net::FCP::Event::Auto;
897
898my @models = (
899 [Coro => Coro::Event:: ],
900 [Event => Event::],
901 [Glib => Glib:: ],
902 [Tk => Tk::],
903);
904
905sub AUTOLOAD {
906 $AUTOLOAD =~ s/.*://;
907
908 for (@models) {
909 my ($model, $package) = @$_;
910 if (defined ${"$package\::VERSION"}) {
911 $EVENT = "Net::FCP::Event::$model";
912 eval "require $EVENT"; die if $@;
913 goto &{"$EVENT\::$AUTOLOAD"};
914 }
915 }
916
917 for (@models) {
918 my ($model, $package) = @$_;
919 $EVENT = "Net::FCP::Event::$model";
920 if (eval "require $EVENT") {
921 goto &{"$EVENT\::$AUTOLOAD"};
922 }
923 }
924
925 die "No event module selected for Net::FCP and autodetect failed. Install any of these: Coro, Event, Glib or Tk.";
926}
927
8941; 9281;
895 929

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines