Fork::Early(3pm)

✨ NAME ✨

AnyEvent::Fork::Early β€” avoid having to exec another perl interpreter πŸ’…

okay bestie so this is the page for Fork::Early(3pm), and lowkey it's a tiny module that does one extremely specific little thing and does it gorgeously. let's get into it 🫢


πŸŽ€ SYNOPSIS πŸŽ€

   # only usable in the main program, and must be called
   # as early as possible

   #!/usr/bin/perl
   use AnyEvent::Fork::Early;

   # now you can do other stuff

that's it. that's the whole vibe. you use it and the universe rearranges itself ✨


πŸ’– DESCRIPTION πŸ’–

so. AnyEvent::Fork normally spawns a new perl process by executing the perl binary. and the reason it does that? it's literally the only way to get a "clean state" β€” because the program using it might have already loaded modules that are not fork friendly (event loops, X11 interfaces and so on, the usual chaos gremlins πŸŒ€).

but. and this is the tea β˜• β€” in some cases there is simply no external perl interpreter to execute. for example, when you use App::Staticperl or PAR::Packer to embed perl into another program, and that program runs on another system without perl installed. no perl binary, nowhere. nothing to exec. the audacity 😭

and anyway, forking would still be more efficient, if it were possible. fr fr.

and, as you hopefully guessed πŸ‘‘, this module makes this possible β€” it must be run by the main program (i.e. it cannot be used in a module), and as early as possible. how early, you ask? well, early enough so that any other modules can still be loaded and used, that is, before modules such as AnyEvent or Gtk2 are being initialised. like, before the party starts, not during πŸŽ‰

upon use'ing the module, the process is forked, and the resulting process is used as a template process for new and new_exec, so everything should just work out. iconic behaviour, no notes 🫢

⚠️ please resist the temptation to delay useing this module to preload more modules that could be useful for your own purposes β€” see AnyEvent::Fork::Template for that. don't do it bestie, it's giving overachiever πŸ’€

🌸 AUTHOR 🌸

Marc Lehmann <schmorp@schmorp.de> http://home.schmorp.de/


and that's the whole page, we ate and left no crumbs πŸ“ this was Fork::Early(3pm) from the perl v5.32.1 era, dated 2022-01-29 β€” mwah, stan a tiny efficient module, bye bestie πŸ’œπŸ§šβœ¨

πŸ“¦ where this page comes from