use Test::StagedFileProducer; my $wherever = '/your/test/directory'; my $producer = Test::StagedFileProducer->new(path => $wherever); $producer->exclude("$wherever/log", "$wherever/build-stamp"); my $output = "$wherever/file.out"; $producer->add_stage( products => [$output], build =>sub { printf "Building $output.\n"; }, skip =>sub { printf "Skipping $output.\n"; } ); $producer->run(minimum_epoch => time, verbose => 1);
After the stages are defined, the processing engine takes an inventory of all files in a target directory. It excludes some files, like logs, that should not be considered.
Each stage adds its own products to the list of files to be excluded before deciding whether to produce them. The decision is based on relative file modification times, in addition to a systemic rebuilding threshold. Before rebuilding, each stage asks a lower stage to make the same determination.
The result is an engine with file production stages that depend on successively larger sets of files.
$HASH{products} => LIST; a list of full-path filenames to be produced.
$HASH{minimum_epoch} => EPOCH; an integer threshold for maximum age
$HASH{build} => SUB; a sub executed when production is required.
$HASH{skip} => SUB; a sub executed when production is not required.
minimum_epoch => EPOCH; a systemic threshold, in epochs, below which rebuilding is mandatory for any product.
verbose => BOOLEAN; an option to enable more verbose reporting
Please note that the bulk of the execution takes place after calling the next lower stage. That is to ensure that any lower build targets (or products, in our parlance) are met before the present stage attempts to do its job.