… | |
… | |
71 | We use C<new_execp> to execute the first F<perl> found in the PATH. You'll |
71 | We use C<new_execp> to execute the first F<perl> found in the PATH. You'll |
72 | have to make sure there is one for this to work. The perl does not |
72 | have to make sure there is one for this to work. The perl does not |
73 | actually have to be the same perl as the one running the example, and it |
73 | actually have to be the same perl as the one running the example, and it |
74 | doesn't need to have any modules installed. |
74 | doesn't need to have any modules installed. |
75 | |
75 | |
76 | The reason we have to specif< C<perl> twice is that the first argument to |
76 | The reason we have to specify C<perl> twice is that the first argument to |
77 | C<new_execp> (and also C<new_exec>) is the program name or path, while |
77 | C<new_execp> (and also C<new_exec>) is the program name or path, while |
78 | the remaining ones are the arguments, and the first argument passed to a |
78 | the remaining ones are the arguments, and the first argument passed to a |
79 | program is the program name, so it has to be specified twice. |
79 | program is the program name, so it has to be specified twice. |
80 | |
80 | |
81 | Finally, the standard example, send some numbers to the remote function, |
81 | Finally, the standard example, send some numbers to the remote function, |
… | |
… | |
125 | use Carp (); |
125 | use Carp (); |
126 | use Errno (); |
126 | use Errno (); |
127 | |
127 | |
128 | use AnyEvent (); |
128 | use AnyEvent (); |
129 | |
129 | |
130 | our $VERSION = 0.2; |
130 | our $VERSION = '1.0'; |
131 | |
131 | |
132 | # xored together must start and and with \n |
132 | # xored together must start and and with \n |
133 | my $magic0 = "Pdk{6y[_zZ"; |
133 | my $magic0 = "Pdk{6y[_zZ"; |
134 | my $magic1 = "Z^yZ7~i=oP"; |
134 | my $magic1 = "Z^yZ7~i=oP"; |
135 | |
135 | |
… | |
… | |
236 | |
236 | |
237 | sub new_from_fh { |
237 | sub 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 | |
246 | sub _new_exec { |
248 | sub _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 | |