Hook::Fork - automatically run code after a fork
use Hook::Fork qw(register_child_fork_hook); register_child_fork_hook { print "fork\n"; }; fork(); # prints "fork" from the child
Forking can often confuse modules; if a parent opens a socket and sets come code to run at DESTROY to close it, that DESTROY will run in both the parent in the child. This means the child exiting can mess up the parent, or the parent exiting can mess up the child.
This module lets you run some code at fork time, so you can setup a new socket for the child, or something similar.
This registers another coderef to run in the child after fork.
This registers another coderef to run in the parent after fork.
This registers another coderef to run before all forks.
All three functions work in the same way.
Normally, it pushes another handler onto the list of hooks
If you call it in scalar context, a guard object will be returned that removes the hook when the guard object goes out of scope.
Otherwise, the hook lives forever.
You can register as many hooks as you like. They run in FIFO order.
http://github.com/jrockway/hook-fork
To contribute, just click "fork", commit changes with impunity, and then send me a pull request. Thanks in advance!
Jonathan Rockway <jrockway@cpan.org>
<jrockway@cpan.org>
Copyright (c) 2010 Jonathan Rockway
This module is free software. You can redistribute it under the same terms as perl itself.
To install Hook::Fork, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hook::Fork
CPAN shell
perl -MCPAN -e shell install Hook::Fork
For more information on module installation, please visit the detailed CPAN module installation guide.