… | |
… | |
16 | |
16 | |
17 | my $fh = $cv->recv; |
17 | my $fh = $cv->recv; |
18 | |
18 | |
19 | =head1 DESCRIPTION |
19 | =head1 DESCRIPTION |
20 | |
20 | |
21 | Despite what the name of this module might suggest, it doesn't actualyl |
21 | Despite what the name of this module might suggest, it doesn't actually |
22 | create remote processes for you. But it does make it easy to use them, |
22 | create remote processes for you. But it does make it easy to use them, |
23 | once you have started them. |
23 | once you have started them. |
24 | |
24 | |
25 | This module implements a very similar API as L<AnyEvent::Fork>. In fact, |
25 | This module implements a very similar API as L<AnyEvent::Fork>. In fact, |
26 | similar enough to require at most minor modifications to support both |
26 | similar enough to require at most minor modifications to support both |
… | |
… | |
103 | -oCheckHostIP=no -oTCPKeepAlive=yes -oStrictHostKeyChecking=no |
103 | -oCheckHostIP=no -oTCPKeepAlive=yes -oStrictHostKeyChecking=no |
104 | -oGlobalKnownHostsFile=/dev/null -oUserKnownHostsFile=/dev/null |
104 | -oGlobalKnownHostsFile=/dev/null -oUserKnownHostsFile=/dev/null |
105 | otherhost |
105 | otherhost |
106 | exec perl); |
106 | exec perl); |
107 | |
107 | |
|
|
108 | =item my $proc = new_execp AnyEvent::Fork::Remote $file, @args... |
|
|
109 | |
|
|
110 | Just like C<new_exec>, except that the program is searched in the |
|
|
111 | C<$ENV{PATH}> first, similarly to how the shell does it. This makes it easier |
|
|
112 | to find e.g. C<ssh>: |
|
|
113 | |
|
|
114 | $proc = new_execp AnyEvent::Fork::Remote "ssh", "ssh", "otherhost", "perl"; |
|
|
115 | |
108 | =item my $proc = new AnyEvent::Fork::Remote $create_callback |
116 | =item my $proc = new AnyEvent::Fork::Remote $create_callback |
109 | |
117 | |
110 | Basically the same as C<new_exec>, but instead of a hardcoded command |
118 | Basically the same as C<new_exec>, but instead of a hardcoded command |
111 | path, it expects a callback which is invoked each time a process needs to |
119 | path, it expects a callback which is invoked each time a process needs to |
112 | be created. |
120 | be created. |
… | |
… | |
169 | shift @fh |
177 | shift @fh |
170 | or Carp::croak "AnyEvent::Fork::Remote::new_from_fh does not support fork"; |
178 | or Carp::croak "AnyEvent::Fork::Remote::new_from_fh does not support fork"; |
171 | }); |
179 | }); |
172 | } |
180 | } |
173 | |
181 | |
174 | sub new_exec { |
182 | sub _new_exec { |
|
|
183 | my $p = pop; |
|
|
184 | |
175 | my ($class, $program, @argv) = @_; |
185 | my ($class, $program, @argv) = @_; |
176 | |
186 | |
177 | require AnyEvent::Util; |
187 | require AnyEvent::Util; |
178 | require Proc::FastSpawn; |
188 | require Proc::FastSpawn; |
179 | |
189 | |
… | |
… | |
187 | open my $oldout, ">&1" or die; |
197 | open my $oldout, ">&1" or die; |
188 | |
198 | |
189 | open STDIN , "<&" . fileno $b or die; |
199 | open STDIN , "<&" . fileno $b or die; |
190 | open STDOUT, ">&" . fileno $b or die; |
200 | open STDOUT, ">&" . fileno $b or die; |
191 | |
201 | |
|
|
202 | $p ? Proc::FastSpawn::spawnp ($program, \@argv) |
192 | Proc::FastSpawn::spawn ($program, \@argv); |
203 | : Proc::FastSpawn::spawn ($program, \@argv); |
193 | |
204 | |
194 | open STDIN , "<&" . fileno $oldin ; |
205 | open STDIN , "<&" . fileno $oldin ; |
195 | open STDOUT, ">&" . fileno $oldout; |
206 | open STDOUT, ">&" . fileno $oldout; |
196 | |
207 | |
197 | $done->($a); |
208 | $done->($a); |
198 | }) |
209 | }) |
|
|
210 | } |
|
|
211 | |
|
|
212 | sub new_exec { |
|
|
213 | push @_, 0; |
|
|
214 | &_new_exec |
|
|
215 | } |
|
|
216 | |
|
|
217 | sub new_execp { |
|
|
218 | push @_, 1; |
|
|
219 | &_new_exec |
199 | } |
220 | } |
200 | |
221 | |
201 | =item $new_proc = $proc->fork |
222 | =item $new_proc = $proc->fork |
202 | |
223 | |
203 | Quite the same as the same method of L<AnyEvent::Fork>, except that it |
224 | Quite the same as the same method of L<AnyEvent::Fork>, except that it |