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

Comparing AnyEvent-Fork/Fork.pm (file contents):
Revision 1.63 by root, Wed Nov 26 13:36:18 2014 UTC vs.
Revision 1.66 by root, Sat Jun 20 13:24:54 2015 UTC

178 178
179=back 179=back
180 180
181=head1 EXAMPLES 181=head1 EXAMPLES
182 182
183This is where the wall of text ends and code speaks.
184
183=head2 Create a single new process, tell it to run your worker function. 185=head2 Create a single new process, tell it to run your worker function.
184 186
185 AnyEvent::Fork 187 AnyEvent::Fork
186 ->new 188 ->new
187 ->require ("MyModule") 189 ->require ("MyModule")
198 200
199 sub worker { 201 sub worker {
200 my ($slave_filehandle) = @_; 202 my ($slave_filehandle) = @_;
201 203
202 # now $slave_filehandle is connected to the $master_filehandle 204 # now $slave_filehandle is connected to the $master_filehandle
203 # in the original prorcess. have fun! 205 # in the original process. have fun!
204 } 206 }
205 207
206=head2 Create a pool of server processes all accepting on the same socket. 208=head2 Create a pool of server processes all accepting on the same socket.
207 209
208 # create listener socket 210 # create listener socket
671 my %env = %ENV; 673 my %env = %ENV;
672 $env{PERL5LIB} = join +($^O eq "MSWin32" ? ";" : ":"), grep !ref, @INC; 674 $env{PERL5LIB} = join +($^O eq "MSWin32" ? ";" : ":"), grep !ref, @INC;
673 675
674 my $pid = Proc::FastSpawn::spawn ( 676 my $pid = Proc::FastSpawn::spawn (
675 $PERL, 677 $PERL,
676 ["perl", "-MAnyEvent::Fork::Serve", "-e", "AnyEvent::Fork::Serve::me", fileno $slave, $$], 678 [$PERL, "-MAnyEvent::Fork::Serve", "-e", "AnyEvent::Fork::Serve::me", fileno $slave, $$],
677 [map "$_=$env{$_}", keys %env], 679 [map "$_=$env{$_}", keys %env],
678 ) or die "unable to spawn AnyEvent::Fork server: $!"; 680 ) or die "unable to spawn AnyEvent::Fork server: $!";
679 681
680 $self->_new ($fh, $pid) 682 $self->_new ($fh, $pid)
681} 683}
717it via C<run>. This also gives you access to any arguments passed via the 719it via C<run>. This also gives you access to any arguments passed via the
718C<send_xxx> methods, such as file handles. See the L<use AnyEvent::Fork as 720C<send_xxx> methods, such as file handles. See the L<use AnyEvent::Fork as
719a faster fork+exec> example to see it in action. 721a faster fork+exec> example to see it in action.
720 722
721Returns the process object for easy chaining of method calls. 723Returns the process object for easy chaining of method calls.
724
725It's common to want to call an iniitalisation function with some
726arguments. Make sure you actually pass C<@_> to that function (for example
727by using C<&name> syntax), and do not just specify a function name:
728
729 $proc->eval ('&MyModule::init', $string1, $string2);
722 730
723=cut 731=cut
724 732
725sub eval { 733sub eval {
726 my ($self, $code, @args) = @_; 734 my ($self, $code, @args) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines