Skip to content

Instantly share code, notes, and snippets.

@realdecisions
Last active January 26, 2016 20:26
Show Gist options
  • Save realdecisions/dbed30507eceb3509b22 to your computer and use it in GitHub Desktop.
Save realdecisions/dbed30507eceb3509b22 to your computer and use it in GitHub Desktop.
package fork::child_cb;
use strict;
my @CHILD_CB;
BEGIN {
*CORE::GLOBAL::fork = sub() {
my $ret = CORE::fork;
if ( defined($ret) && $ret == 0 ) {
$_->() for @CHILD_CB;
}
return $ret;
};
}
sub add(&) {
push @CHILD_CB, $_[0];
1;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment