ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/AnyEvent-Fork/Fork/Early.pm
Revision: 1.11
Committed: Sun Jul 18 06:42:34 2021 UTC (5 years, 3 months ago) by root
Branch: MAIN
CVS Tags: rel-1_32, HEAD
Changes since 1.10: +0 -3 lines
Log Message:
bad idea

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     AnyEvent::Fork::Early - avoid having to exec another perl interpreter
4    
5     =head1 SYNOPSIS
6    
7     # only usable in the main program, and must be called
8     # as early as possible
9    
10     #!/usr/bin/perl
11     use AnyEvent::Fork::Early;
12    
13     # now you can do other stuff
14    
15     =head1 DESCRIPTION
16    
17     L<AnyEvent::Fork> normally spawns a new perl process by executing the perl
18     binary. It does this because it is the only way to get a "clean state", as
19     the program using it might have loaded modules that are not fork friendly
20     (event loops, X11 interfaces and so on).
21    
22     However, in some cases, there is no external perl interpreter to execute,
23     for example, when you use L<App::Staticperl> or L<PAR::Packer> to embed
24     perl into another program, and that program runs on another system without
25     perl installed.
26    
27     And anyway, forking would still be more efficient, if it were possible.
28    
29     And, as you hopefully guessed, this module makes this possible - it must
30     be run by the main program (i.e. to cannot be used in a module), and as
31     early as possible. How early? Well, early enough so that any other modules
32 root 1.8 can still be loaded and used, that is, before modules such as AnyEvent or
33 root 1.1 Gtk2 are being initialised.
34    
35     Upon C<use>'ing the module, the process is forked, and the resulting
36     process is used as a template process for C<new> and C<new_exec>, so
37     everything should just work out.
38    
39     Please resist the temptation to delay C<use>ing this module to
40     preload more modules that could be useful for your own purposes, see
41     L<AnyEvent::Fork::Template> for that.
42    
43     =cut
44    
45     package AnyEvent::Fork::Early;
46    
47     # load stuff we need anyways
48     use AnyEvent::Fork ();
49    
50 root 1.4 # this does not work on win32, due to the atrociously bad fake perl fork
51 root 1.7 unless ($^O eq "MSWin32") {
52 root 1.4 # we preload certain modules because sooner or later, somebody will use them.
53     # complain to me if that causes trouble.
54     require common::sense;
55     require strict;
56     require warnings;
57 root 1.5 require feature if $] >= 5.010;
58 root 1.4 require Carp;
59    
60 root 1.7 require IO::FDPass;
61    
62 root 1.4 $AnyEvent::Fork::TEMPLATE =
63 root 1.6 $AnyEvent::Fork::EARLY = AnyEvent::Fork->_new_fork ("AnyEvent::Fork::Early");
64 root 1.4 }
65 root 1.1
66     =head1 AUTHOR
67    
68     Marc Lehmann <schmorp@schmorp.de>
69     http://home.schmorp.de/
70    
71     =cut
72    
73     1
74