NAME Test::File::Cleaner - Automatically clean up your filesystem after tests SYNOPSIS # Create the cleaner my $Cleaner = Test::File::Cleaner->new( 'file_dmz' ); # Do some tests that create files touch 'file_dmz/foo'; # Cleaner cleans when it is DESTROYed exit(); # Alternatively, force an immediate clean up $Cleaner->clean; DESCRIPTION When writing file-related testing code, it is common to end up with a number of files scattered all over the testing directories. If you are running the test scripts over and over these leftover files can interfere with subsequent test runs, and so they need to be cleaned up. This clean up code typically needs to be done at END-time, so that the files are cleaned up even if you break out of the test script while it is running. The code to do this can get long and is labourious to maintain. Test::File::Cleaner attempts to solve this problem. When you create a Cleaner object for a particular directory, the object scans and saves the contents of the directory. When the object is DESTROYed, it compares the current state to the original, and removes any new files and directories created during the testing process. METHODS new $dir Creates a new Test::File::Cleaner object, which will automatically clean when it is destroyed. The cleaner is passed a directory within which it will operate, which must exist. Since this is intended to be used in test scripts, it will die on error. You will not need to test the return value. path The "path" accessor returns the current root path for the object. The root path cannot be changed once the Test::File::Cleaner object has been created. clean Calling the "clean" method forces a clean of the directory. The Cleaner will scan it's directory, compare what it finds with it's original scan, and then do whatever is needed to restore the directory to it's original state. Returns true if the Cleaner fully restores the directory, or false otherwise. reset The "reset" method assumes you want to keep any changes that have been made, and will rescan the directory and store the new state instead. Returns true of die on error Test::File::Cleaner::State A Test::File::Cleaner::State object stores the state information for a single file or directory, and performs tasks to restore old states. new $file Creates a new State object for a given file name. The file or directory must exist. Returns a new Test::File::Cleaner::State object, or dies on error. path Returns the path of the file dir Returns true if the state object is a directory Stat Returns the File::stat object for the file mode Returns the permissions mode for the file/directory clean Cleans the state object, by examining the new state of the file, and reverting it to the old one if possible. remove The "remove" method deletes a file for which we are holding a state. The reason we provide a special method for this is that in some situations, a file permissions may not allow us to remove it, and thus we may need to correct it's permissions first. SUPPORT Bugs should be submitted via the CPAN bug tracker, located at For other issues, or commercial enhancement or support, contact the author.. AUTHOR Adam Kennedy (Maintainer), , cpan@ali.as COPYRIGHT Thank you to Phase N Australia () for permitting the open sourcing and release of this distribution as a spin-off from a commercial project. Copyright (c) 2004 Adam Kennedy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module.