… | |
… | |
34 | |
34 | |
35 | The import tag to use is named C<event=xyz>, e.g. C<event=Event>, |
35 | The import tag to use is named C<event=xyz>, e.g. C<event=Event>, |
36 | C<event=Glib> etc. |
36 | C<event=Glib> etc. |
37 | |
37 | |
38 | You should specify the event module to use only in the main program. |
38 | You should specify the event module to use only in the main program. |
|
|
39 | |
|
|
40 | If no event model has been specified, FCP tries to autodetect it on first |
|
|
41 | use (e.g. first transaction), in this order: Coro, Event, Glib, Tk. |
39 | |
42 | |
40 | =head2 FREENET BASICS |
43 | =head2 FREENET BASICS |
41 | |
44 | |
42 | Ok, this section will not explain any freenet basics to you, just some |
45 | Ok, this section will not explain any freenet basics to you, just some |
43 | problems I found that you might want to avoid: |
46 | problems I found that you might want to avoid: |
… | |
… | |
69 | |
72 | |
70 | package Net::FCP; |
73 | package Net::FCP; |
71 | |
74 | |
72 | use Carp; |
75 | use Carp; |
73 | |
76 | |
74 | $VERSION = 0.07; |
77 | $VERSION = 0.08; |
75 | |
78 | |
76 | no warnings; |
79 | no warnings; |
77 | |
80 | |
78 | our $EVENT = Net::FCP::Event::Auto::; |
81 | our $EVENT = Net::FCP::Event::Auto::; |
79 | $EVENT = Net::FCP::Event::Event;#d# |
|
|
80 | |
82 | |
81 | sub import { |
83 | sub 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 | |
93 | sub touc($) { |
95 | sub touc($) { |
94 | local $_ = shift; |
96 | local $_ = shift; |
… | |
… | |
773 | sub rcv_data { |
775 | sub 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 | |
|
|
896 | package Net::FCP::Event::Auto; |
|
|
897 | |
|
|
898 | my @models = ( |
|
|
899 | [Coro => Coro::Event:: ], |
|
|
900 | [Event => Event::], |
|
|
901 | [Glib => Glib:: ], |
|
|
902 | [Tk => Tk::], |
|
|
903 | ); |
|
|
904 | |
|
|
905 | sub 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 | |
894 | 1; |
928 | 1; |
895 | |
929 | |