| line | stmt | bran | cond | sub | pod | time | code | 
| 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 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 or L 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 |  |  |  |  |  |  | can still be loaded and used, that is, before modules such as AnyEvent or | 
| 33 |  |  |  |  |  |  | Gtk2 are being initialised. | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | Upon C | 
| 36 |  |  |  |  |  |  | process is used as a template process for C and C, so | 
| 37 |  |  |  |  |  |  | everything should just work out. | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | Please resist the temptation to delay C | 
| 40 |  |  |  |  |  |  | preload more modules that could be useful for your own purposes, see | 
| 41 |  |  |  |  |  |  | L for that. | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | =cut | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | package AnyEvent::Fork::Early; | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | # load stuff we need anyways | 
| 48 | 3 |  |  | 3 |  | 3354 | use AnyEvent::Fork (); | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 282 |  | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # this does not work on win32, due to the atrociously bad fake perl fork | 
| 51 |  |  |  |  |  |  | unless ($^O eq "MSWin32") { | 
| 52 |  |  |  |  |  |  | # 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 |  |  |  |  |  |  | require feature if $] >= 5.010; | 
| 58 |  |  |  |  |  |  | require Carp; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | require IO::FDPass; | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | $AnyEvent::Fork::TEMPLATE = | 
| 63 |  |  |  |  |  |  | $AnyEvent::Fork::EARLY    = AnyEvent::Fork->_new_fork ("AnyEvent::Fork::Early"); | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head1 AUTHOR | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | Marc Lehmann | 
| 69 |  |  |  |  |  |  | http://home.schmorp.de/ | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =cut | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | 1 | 
| 74 |  |  |  |  |  |  |  |