… | |
… | |
6 | |
6 | |
7 | use AnyEvent::FCP; |
7 | use AnyEvent::FCP; |
8 | |
8 | |
9 | my $fcp = new AnyEvent::FCP; |
9 | my $fcp = new AnyEvent::FCP; |
10 | |
10 | |
11 | # transactions return condvars |
11 | # transactions return condvars |
12 | my $lp_cv = $fcp->list_peers; |
12 | my $lp_cv = $fcp->list_peers; |
13 | my $pr_cv = $fcp->list_persistent_requests; |
13 | my $pr_cv = $fcp->list_persistent_requests; |
14 | |
14 | |
15 | my $peers = $lp_cv->recv; |
15 | my $peers = $lp_cv->recv; |
16 | my $reqs = $pr_cv->recv; |
16 | my $reqs = $pr_cv->recv; |
… | |
… | |
26 | The module uses L<AnyEvent> to find a suitable event module. |
26 | The module uses L<AnyEvent> to find a suitable event module. |
27 | |
27 | |
28 | Only very little is implemented, ask if you need more, and look at the |
28 | Only very little is implemented, ask if you need more, and look at the |
29 | example program later in this section. |
29 | example program later in this section. |
30 | |
30 | |
|
|
31 | =head2 EXAMPLE |
|
|
32 | |
|
|
33 | This example fetches the download list and sets the priority of all files |
|
|
34 | with "a" in their name to "emergency": |
|
|
35 | |
|
|
36 | use AnyEvent::FCP; |
|
|
37 | |
|
|
38 | my $fcp = new AnyEvent::FCP; |
|
|
39 | |
|
|
40 | $fcp->watch_global_sync (1, 0); |
|
|
41 | my $req = $fcp->list_persistent_requests_sync; |
|
|
42 | |
|
|
43 | for my $req (values %$req) { |
|
|
44 | if ($req->{filename} =~ /a/) { |
|
|
45 | $fcp->modify_persistent_request_sync (1, $req->{identifier}, undef, 0); |
|
|
46 | } |
|
|
47 | } |
|
|
48 | |
31 | =head2 IMPORT TAGS |
49 | =head2 IMPORT TAGS |
32 | |
50 | |
33 | Nothing much can be "imported" from this module right now. |
51 | Nothing much can be "imported" from this module right now. |
34 | |
52 | |
35 | =head2 THE AnyEvent::FCP CLASS |
53 | =head2 THE AnyEvent::FCP CLASS |
… | |
… | |
42 | |
60 | |
43 | use common::sense; |
61 | use common::sense; |
44 | |
62 | |
45 | use Carp; |
63 | use Carp; |
46 | |
64 | |
47 | our $VERSION = '0.21'; |
65 | our $VERSION = '0.3'; |
48 | |
66 | |
49 | use Scalar::Util (); |
67 | use Scalar::Util (); |
50 | |
68 | |
51 | use AnyEvent; |
69 | use AnyEvent; |
52 | use AnyEvent::Handle; |
70 | use AnyEvent::Handle; |
… | |
… | |
95 | my $self = bless { @_ }, $class; |
113 | my $self = bless { @_ }, $class; |
96 | |
114 | |
97 | $self->{host} ||= $ENV{FREDHOST} || "127.0.0.1"; |
115 | $self->{host} ||= $ENV{FREDHOST} || "127.0.0.1"; |
98 | $self->{port} ||= $ENV{FREDPORT} || 9481; |
116 | $self->{port} ||= $ENV{FREDPORT} || 9481; |
99 | $self->{name} ||= time.rand.rand.rand; # lame |
117 | $self->{name} ||= time.rand.rand.rand; # lame |
100 | $self->{timeout} ||= 600; |
118 | $self->{timeout} ||= 3600*2; |
101 | $self->{progress} ||= sub { }; |
119 | $self->{progress} ||= sub { }; |
102 | |
120 | |
103 | $self->{id} = "a0"; |
121 | $self->{id} = "a0"; |
104 | |
122 | |
105 | { |
123 | { |
… | |
… | |
107 | |
125 | |
108 | $self->{hdl} = new AnyEvent::Handle |
126 | $self->{hdl} = new AnyEvent::Handle |
109 | connect => [$self->{host} => $self->{port}], |
127 | connect => [$self->{host} => $self->{port}], |
110 | timeout => $self->{timeout}, |
128 | timeout => $self->{timeout}, |
111 | on_error => sub { |
129 | on_error => sub { |
112 | warn "<@_>\n"; |
130 | warn "@_\n";#d# |
113 | exit 1; |
131 | exit 1; |
114 | }, |
132 | }, |
115 | on_read => sub { $self->on_read (@_) }, |
133 | on_read => sub { $self->on_read (@_) }, |
116 | on_eof => $self->{on_eof} || sub { }; |
134 | on_eof => $self->{on_eof} || sub { }; |
117 | |
135 | |