NAME

Object::Wrapper::Fork -- Practice safe forks: use a hat.

SYNOPSIS

pacakge My;

# parent is lighter weight than base if it
# is available.

use parent qw( Object::Wrapper::Fork );

sub cleanup
{
    # validate 

    my ( $object, $pid ) = @_;

    if( $pid == $$ )
    {
        # clean up within same process
    }
    else
    {
        # clean up post-fork.
    }
}

sub new
{
    # build the object Your Way. 
    # Object::Wrapper::Fork supplies the pid 
    # ($$) when wrapping and AUTOLOAD to 
    # validate it againsed the current pid.

    my $object  = UnforkSafe->new( @blah );

    __PACKAGE__->SUPER::new( $object )
}

DESCRIPTION

Use Safe Forks: Wear a hat.

Any number of modules cannot gracefully handle re-use across forks. This module provides a simple wrapper that re-validates the pid on calls and calls a cleanup handler with the original PID when destroyed.

The bulk of the work is done in AUTOLOAD, which re-validates the pid and passes the original object by reference for each call made (i.e., modifications to the object via $_[0] are propagated).

DESTROY calls the wrapped object with its original pid, which can be compared to $$ for appropriate behavior. Passing the PID pback can simplify logging messages or help packages that track PID's.

Interface

new

This takes a reference to the object or package being wrapped and returns the wrapper. It would normaly be called from the wrapped objects constructor:

sub Your::Constructor
{
    my $proto   = shift;

    my $thingy  = $madness->$method( @argz );

    $proto->SUPER::new( $thingy )
}

NOTES

Tied Objects

This will not handle tied objects gracefully. If you're into BSDM then you're out of luck here. Sorry.

SEE ALSO

Object::Wrapper

Generic constructor takes list of arguments added to the object for validation by its AUTOLOAD and cleanup methods.

Object::Wrapper::Fork::DBI

Fork wrapper for DBI database handles. Supplies a "connect" method and cleanup handler for dealing with CackedKids and InactiveDestroy vs. finish/disconnect.

AUTHOR

Steven Lembark <lembark@wrkhors.com>

COPYRIGHT

Copyright (C) 2009 Steven Lembark. This module is released under the same terms as Perl-5.10.0 itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 139:

You forgot a '=back' before '=head1'