Jonathan Rockway > Hook-Fork-0.01_01 > Hook::Fork

Download:
Hook-Fork-0.01_01.tar.gz

Dependencies

Annotate this POD

Module Version: 0.01_01   Source  

NAME ^

Hook::Fork - automatically run code after a fork

SYNOPSIS ^

    use Hook::Fork qw(register_child_fork_hook);
    register_child_fork_hook {
        print "fork\n";
    };

    fork();
    # prints "fork" from the child

DESCRIPTION ^

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.

FUNCTIONS ^

register_child_fork_hook(&)

This registers another coderef to run in the child after fork.

register_parent_fork_hook(&)

This registers another coderef to run in the parent after fork.

register_before_fork_hook(&)

This registers another coderef to run before all forks.

DETAILS ^

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.

REPOSITORY ^

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!

AUTHOR ^

Jonathan Rockway <jrockway@cpan.org>

COPYRIGHT ^

Copyright (c) 2010 Jonathan Rockway

This module is free software. You can redistribute it under the same terms as perl itself.

syntax highlighting: