A software that enables transactional change to a group of files.
If you need to add files to the transaction, it's critical to consider the order that you do it. Files will be committed in the order they're added to the transaction. Therefore, the order in which you add them should be chosen with care to limit the damage to your data if the commit() fails part way through. In case there's no order that renders a partial commit acceptable, consider using File::Transaction::Atomic instead.
To demonstrate how to use this module, consider the following example where we want to replace the word 'foo' with 'bar' in several files. We want to minimize the risk of ending up with the replacement done in some files but not others. We achieve this by using the linewise_rewrite method as follows:
use File::Transaction;
my $ft = File::Transaction->new;
eval {
foreach my $file (@list_of_file_names) {
$ft->linewise_rewrite($file, sub {
s#foo#bar#g;
});
}
};
if ($@) {
$ft->revert;
die "update aborted: $@";
} else {
$ft->commit;
}
In summary, File::Transaction provides an excellent way to perform changes to sets of files while keeping them consistent. Keep in mind the order in which the files are added to the transaction and consider using File::Transaction::Atomic if a partial commit isn't acceptable. Overall, we recommend this module for any project that involves making filesystem modifications.
Version 1.00: N/A