According to the documentation of ExtTools::Util::FAQ, a good way to handle automatically revisions can be the exploiting the Version Control System for it.
I've learned about git attributes, and they can be used for it as follows:
In every module replace the
package <name> <version>
with some conventional placeholder string.-package PFT v1.0.1; +package PFT GitVersion;
I've also added a
FullVersion
variable to hold a more specific versioning information (that is the output ofgit describe
).+our $FullVersion = 'GitVersionFull';
Smudge filter (described in gitattributes (5))
#!/bin/perl -wp -CSDL BEGIN { chomp($::version = `git describe --abbrev=0`); chomp($::version_full = `git describe --abbrev=7`); } s/^(\s*our\s+\$FullVersion\s+=\s+')GitVersionFull('\s*;\s*)$/$1$::version_full$2/g; s/^(\s*package\s\S+\s)GitVersion(.*)$/$1$::version$2/g;
Clean filter (also described in gitattributes (5))
#!/bin/perl -wp -CSDL BEGIN { chomp(my $v = `git describe --abbrev=0`); $::version = qr/\Q$v\E/; $::version_full = qr/\Q$v\E-\d+-g.{7}/; # In version_full, .{7} represents the 7 digits of --abbrev=7 # in smudge. } s/^(\s*our\s+\$FullVersion\s+=\s+')$::version_full('\s*;\s*)$/$1GitVersionFull$2/g; s/^(\s*package\s\S+\s)$::version(.*)$/$1GitVersion$2/g;
- Setup with
git config filter.fixversion.smudge $path_smudge
andgit config filter.fixversion.clean $path_clean
, where$path_smudge
and$path_clean
are relative path from the project root directory.
- Setup with
The trick works really well, but has a huge disadvantage: If the new
developer doesn't know about it and didn't set up the filters as in the
last step, loading the modules will result in errors (GitVersion
is not
a valid symbol).
Then, as mentioned by the git attributes (5), there's more complexity involved, possibly resulting in merge conflicts. In fact, the filters are actually intended as convenience, not as requirement:
One use of the content filtering is to massage the content into a shape that is more convenient for the platform, filesystem, and the user to use. For this mode of operation, the key phrase here is "more convenient" and not "turning something unusable into usable". In other words, the intent is that if someone unsets the filter driver definition, or does not have the appropriate filter program, the project should still be usable.
A related discussion on Stack Overflow points me to the
ppi_version
tool, available in Fedora as perl-PPI-PowerToys
.
Probably this deserves some investigation.