ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Fork-Remote/Remote.pm
(Generate patch)

Comparing AnyEvent-Fork-Remote/Remote.pm (file contents):
Revision 1.2 by root, Sat Apr 27 23:59:04 2013 UTC vs.
Revision 1.3 by root, Sun Apr 28 01:04:00 2013 UTC

16 16
17 my $fh = $cv->recv; 17 my $fh = $cv->recv;
18 18
19=head1 DESCRIPTION 19=head1 DESCRIPTION
20 20
21Despite what the name of this module might suggest, it doesn't actualyl 21Despite what the name of this module might suggest, it doesn't actually
22create remote processes for you. But it does make it easy to use them, 22create remote processes for you. But it does make it easy to use them,
23once you have started them. 23once you have started them.
24 24
25This module implements a very similar API as L<AnyEvent::Fork>. In fact, 25This module implements a very similar API as L<AnyEvent::Fork>. In fact,
26similar enough to require at most minor modifications to support both 26similar 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
110Just like C<new_exec>, except that the program is searched in the
111C<$ENV{PATH}> first, similarly to how the shell does it. This makes it easier
112to 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
110Basically the same as C<new_exec>, but instead of a hardcoded command 118Basically the same as C<new_exec>, but instead of a hardcoded command
111path, it expects a callback which is invoked each time a process needs to 119path, it expects a callback which is invoked each time a process needs to
112be created. 120be 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
174sub new_exec { 182sub _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
212sub new_exec {
213 push @_, 0;
214 &_new_exec
215}
216
217sub 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
203Quite the same as the same method of L<AnyEvent::Fork>, except that it 224Quite the same as the same method of L<AnyEvent::Fork>, except that it

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines