Stepford::Role::Step::FileGenerator::Atomic - A role for steps that generate a file atomically
version 0.006001
This role consumes the Stepford::Role::Step::FileGenerator role. It allows only one file production, but makes sure it is written atomically - the file will not exist if the step aborts. The file will only be committed to its final destination when run completes successfully.
run
Instead of manipulating the file production directly, you work with the file given by $step->pre_commit_file. This role will make sure it gets committed after run.
$step->pre_commit_file
This role provides the following methods:
This method adds a wrapper to the BUILD method which ensures that there is only one production.
This returns a temporary file in a temporary directory that you can manipulate inside run. It will be removed if the step fails, or renamed to the final file production if the step succeeds.
When running steps in parallel, it is important to ensure that you do not call the $step->pre_commit_file method outside of the $step->run method. If you call this at object creation time, this can cause the tempdir containing the pre_commit_file file to be created and destroyed before the run method ever gets a chance to run.
$step->run
pre_commit_file
Bugs may be submitted through https://github.com/maxmind/Stepford/issues.
Dave Rolsky <drolsky@maxmind.com>
This software is copyright (c) 2014 - 2023 by MaxMind, Inc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Stepford, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Stepford
CPAN shell
perl -MCPAN -e shell install Stepford
For more information on module installation, please visit the detailed CPAN module installation guide.