1 |
=head1 NAME |
2 |
|
3 |
AnyEvent::Fork::Template - generate a template process from the main program |
4 |
|
5 |
=head1 SYNOPSIS |
6 |
|
7 |
# only usable in the main program |
8 |
|
9 |
# preload some harmless modules (just examples) |
10 |
use Other::Module; |
11 |
use Some::Harmless::Module; |
12 |
use My::Worker::Module; |
13 |
|
14 |
# now fork and keep the template |
15 |
use AnyEvent::Fork::Template; |
16 |
|
17 |
# now do less harmless stuff (just examples) |
18 |
use Gtk2 -init; |
19 |
my $w = AE::io ...; |
20 |
|
21 |
# and finally, use the template to run some workers |
22 |
$AnyEvent::Fork::Template->fork->run ("My::Worker::Module::run_worker", sub { ... }); |
23 |
|
24 |
=head1 DESCRIPTION |
25 |
|
26 |
By default, this module forks when it is used the first time and stores |
27 |
the resulting L<AnyEvent::Fork> object in the C<$AnyEvent::Fork::Template> |
28 |
variable (mnemonic: same name as the module itself). |
29 |
|
30 |
It must only be used in the main program, and only once. Other than that, |
31 |
the only requirement is that you can handle the results of a fork at that |
32 |
time, i.e., when you use this module after AnyEvent has been initialised, |
33 |
or use it after you opened some window with Gtk2 or Tk for example then |
34 |
then you can't easily use these modules in the forked process. Choosing |
35 |
the place to use this module wisely is key. |
36 |
|
37 |
There is never a need for this module - you can always create a new empty |
38 |
process and loading the modules you need into it. |
39 |
|
40 |
=cut |
41 |
|
42 |
package AnyEvent::Fork::Template; |
43 |
|
44 |
use AnyEvent::Fork (); |
45 |
|
46 |
# this does not work on win32, due to the atrociously bad fake perl fork |
47 |
die "AnyEvent::Fork::Template does not work on WIN32 due to bugs in perl\n" |
48 |
if $^O eq "MSWin32"; |
49 |
|
50 |
$AnyEvent::Fork::Template = AnyEvent::Fork->_new_fork ("AnyEvent::Fork::Template"); |
51 |
|
52 |
=head1 AUTHOR |
53 |
|
54 |
Marc Lehmann <schmorp@schmorp.de> |
55 |
http://home.schmorp.de/ |
56 |
|
57 |
=cut |
58 |
|
59 |
1 |
60 |
|