NAME

Util::SelfDestruct - Conditionally prevent execution of a script

SYNOPSIS

# Immediately prevent execution of script by dying on invocation
# if it has already been executed once before. (The default behavior
# is to self destruct by dying, unless instructed otherwise).
use Util::SelfDestruct;
 
# Delete the script after it is executed
use Util::SelfDestruct('unlink');
 
# Prevent execution of the script by dying if it
# is executed after Dec 17th 2005 at 6pm
use Util::SelfDestruct(after => '2005-12-17 18h00m00s');
 
# Delete the script after execution, if it is executed
# between 1st Dec 2005 and 17th Dec 2005 at 4:05pm
use Util::SelfDestruct('unlink', 
                       after => '2005-12-01',
                       before => '2005-12-17 16:05:00',
                   );

DESCRIPTION

This module will prevent execution of your script by either dying or deleting (unlinking) the script from disk after it is executed. This can be useful if you have written a script for somebody that must never be executed more than once. A database upgrade script for example.

The 'self destruct' mechanism can be achieved through deleting the script so that it cannot be executed again, or by dying (terminating the scripts execution).

Die Method (default)

This is the default, and safest behaviour. This allows the script to be executed once. If it is executed again, it will immediately die during the initial compilation phase, preventing the script from fully executing.

To do this, the Util::SelfDestruct needs to know if the calling script has ever been executed before. It does this by writing a memo to a file called .selfdestruct in the user's home directory whenever the script is executed. It can therefore find out if the script has been run before during subsequent invocations.

This method should be used with caution. To specify the unlink method, add the unlink boolean flag as an import paramter (see examples in the synopsis above). Aliases for the unlink flag are erase and delete.

This method will allow the script to execute, but then delete the file during the cleanup phase after execution. (Specifically during the execution of the END{} in the Util::SelfDestruct module).

AUDIENCE

System Administrators & script monkeys

TODO

Improve/finish the POD.

Write the code that writes invocation history to ~/.selfdestruct for use with the default die mechanism.

Write the code to handle use of both before and after at the same time.

Write unit tests.

VERSION

$Revision: 1.7 $

AUTHOR

Nicola Worthington <nicolaw@cpan.org>

http://www.nicolaworthington.com

$Author: nicolaw $