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.5 by root, Sun Apr 28 15:36:30 2013 UTC vs.
Revision 1.7 by root, Sat May 21 07:37:04 2016 UTC

71We use C<new_execp> to execute the first F<perl> found in the PATH. You'll 71We use C<new_execp> to execute the first F<perl> found in the PATH. You'll
72have to make sure there is one for this to work. The perl does not 72have to make sure there is one for this to work. The perl does not
73actually have to be the same perl as the one running the example, and it 73actually have to be the same perl as the one running the example, and it
74doesn't need to have any modules installed. 74doesn't need to have any modules installed.
75 75
76The reason we have to specif< C<perl> twice is that the first argument to 76The reason we have to specify C<perl> twice is that the first argument to
77C<new_execp> (and also C<new_exec>) is the program name or path, while 77C<new_execp> (and also C<new_exec>) is the program name or path, while
78the remaining ones are the arguments, and the first argument passed to a 78the remaining ones are the arguments, and the first argument passed to a
79program is the program name, so it has to be specified twice. 79program is the program name, so it has to be specified twice.
80 80
81Finally, the standard example, send some numbers to the remote function, 81Finally, the standard example, send some numbers to the remote function,
125use Carp (); 125use Carp ();
126use Errno (); 126use Errno ();
127 127
128use AnyEvent (); 128use AnyEvent ();
129 129
130our $VERSION = 0.2; 130our $VERSION = '1.0';
131 131
132# xored together must start and and with \n 132# xored together must start and and with \n
133my $magic0 = "Pdk{6y[_zZ"; 133my $magic0 = "Pdk{6y[_zZ";
134my $magic1 = "Z^yZ7~i=oP"; 134my $magic1 = "Z^yZ7~i=oP";
135 135
236 236
237sub new_from_fh { 237sub new_from_fh {
238 my ($class, @fh) = @_; 238 my ($class, @fh) = @_;
239 239
240 $class->new (sub { 240 $class->new (sub {
241 shift @fh 241 my $fh = shift @fh
242 or Carp::croak "AnyEvent::Fork::Remote::new_from_fh does not support fork"; 242 or Carp::croak "AnyEvent::Fork::Remote::new_from_fh does not support fork";
243
244 $_[0]($fh);
243 }); 245 });
244} 246}
245 247
246sub _new_exec { 248sub _new_exec {
247 my $p = pop; 249 my $p = pop;
424 my $fh = shift 426 my $fh = shift
425 or die "AnyEvent::Fork::Remote: create callback failed"; 427 or die "AnyEvent::Fork::Remote: create callback failed";
426 428
427 my $owner = length $ENV{HOSTNAME} ? "$ENV{HOSTNAME}:$$" : "*:$$"; 429 my $owner = length $ENV{HOSTNAME} ? "$ENV{HOSTNAME}:$$" : "*:$$";
428 430
429 my $code = 'BEGIN { $0 = ' . (sq "$func of $owner") . '; ' . $self->[1] . "}\n" 431 my $code = 'BEGIN { $0 = ' . (sq "$owner $func") . '; ' . $self->[1] . "}\n"
430 . 'syswrite STDOUT, ' . (sq $magic0) . '^' . (sq $magic1) . ';' 432 . 'syswrite STDOUT, ' . (sq $magic0) . '^' . (sq $magic1) . ';'
431 . '{ sysread STDIN, my $dummy, 1 }' 433 . '{ sysread STDIN, my $dummy, 1 }'
432 . "\n$func*STDIN," . (aq @{ $self->[2] }) . ';' 434 . "\n$func*STDIN," . (aq @{ $self->[2] }) . ';'
433 . "\n__END__\n"; 435 . "\n__END__\n";
434 436

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines