Corion has asked for the wisdom of the Perl Monks concerning the following question:

I'm not looking for the next Module::Build. I'm also not looking for make. What I'm looking for is some functionality that I've implemented myself in various bad and ad-hoc ways:

I'm generating some output files, which usually depend on one or more input files. And as this is a lengthy process, I only want to do that if some condition holds. That condition usually is that minimum last change timestamps of the output files is later than the maximum last change timetamp of all input files, that is, all output files were created later than the last input file was changed.

Now, the basic Perl code for this is

if ((stat($target))[9] < (stat($source))[9]) { ... do work ... }

but that only covers one target depending on one source file. Also, this gets complicated, because from time to time, you want to ignore all that smartness and force a clean slate by regenerating everything anyway:

if ($force or (stat($target))[9] < (stat($source))[9]) { ... do work ... }

So, what I'd like would be something that I preconfigure and which then handles those dependencies for me and invokes my callback. Maybe like this:

GetOptions( 'f' => \my $force, 'o' => \my $outdir, ); $outdir ||= 'thumbnails'; my $needs_remake = My::Dependencies::MTime->new( force => $force ); for my $source_image (@ARGV) { if ($needs_remake->([$source_image], ["$outdir/${source_image}_t.j +pg"])) { ... do work here }; };

... except that this API doesn't look quite usable to me, and worst of all, I would need to write it myself, again. So, maybe somebody has already written and tested that code for me, or maybe somebody is even a user of code that somebody else has written, and I don't know about the module. Please tell me whether the Easter Bunny has left this on CPAN already, and where.

I've already looked at the following modules:

Currently, I've somewhat uneasily settled on Decision::Depends with the following construct:

if (test_dep( -target => $thumbname, -depend => $info->{file} )) { ... }

... which still is a bit more verbose than I'd like it to be, but then again, I didn't need to write any code myself. Still, other recommendations are welcome!

Replies are listed 'Best First'.
Re: A module encapsulating "make"-like checks
by jdporter (Paladin) on Apr 04, 2010 at 22:03 UTC

    You might take a look at make.pl (indexed here). It is billed as "make with Perl as the rule language. Write a plain makefile in Perl syntax, or write a program [which] does a few file-dependency driven things." Unfortunately it's written as a monolithic program, but you could probably easily modularize it.

    Then there's cons — "a replacement for make. It is not compatible with make, but it has a number of powerful capabilities not found in other software construction systems, including make. ... It is implemented in Perl. You don't need to know Perl to use cons, although you can use it more powerfully if you do." I haven't looked; maybe it has a modular API you could use or extract.

    What is the sound of Windows? Is it not the sound of a wall upon which people have smashed their heads... all the way through?