File::Transaction

Transactional change to a set of files
Download

File::Transaction Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Nick Cleaton
  • Publisher web site:
  • http://search.cpan.org/~ncleaton/

File::Transaction Tags


File::Transaction Description

Transactional change to a set of files The File::Transaction object encapsulates a change to a set of files, performed by writing out a new version of each file first and then swapping all of the new versions in. The set of files can only end up in an inconsistent state if a rename system call fails or if the Perl process is interrupted during the commit().Files will be committed in the order in which they are added to the transaction. This order should be chosen with care to limit the damage to your data if the commit() fails part way through. If there is no order that renders a partial commit acceptable then consider using File::Transaction::Atomic instead.SYNOPSIS # # In this example, we wish to replace the word 'foo' with the # word 'bar' in several files, and we wish to minimize the risk # of ending up with the replacement done in some files but not # in others. # 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; } Requirements: · Perl


File::Transaction Related Software