Приглашаем посетить
Грибоедов (griboedov.lit-info.ru)

10.5 Version Control System Integration

Previous Table of Contents Next

10.5 Version Control System Integration

If you're using Revision Control System (RCS), you might like to have the RCS version number automatically be used as the version number of your code. The package variable $VERSION should be set in a module because various tools will look for it. However, you can't just say:


our $VERSION = '$Revision$';

because version numbers need to be numeric. What you need is an expression that incorporates the RCS Revision keyword and returns the numeric component of it. Here's one possibility:


our $VERSION = (qw$Revision: 3.42 $)[-1];

which cunningly uses the RCS $ keyword delimiter as the delimiter for the qw operator, extracting just the number 3.42 from the second space-separated component.

If you prefer more than two components to your version numbers, the ExtUtils::MakeMaker documentation shows an alternative approach:


our $VERSION = do { my @r = (q$Revision: 1.2.3 $ =~ /\d+/g); \ 

sprintf "%d."."%03d" x $#r, @r };

For MakeMaker to recognize this as a $VERSION assignment, all that code must be on one line.

Concurrent Versions System (CVS) uses the same keywords. Source Code Control Systems (SCCS) is used far less frequently than either RCS or CVS, but it would be trivial to do version numbering with it:


our $VERSION = "%I%";

Note the quotation marks: Perl has allowed v-strings for several versions (numbers that contain more than one period; they get turned into a binary form), but they were deprecated for versions of Perl after 5.8.1, so I conservatively stringified the version.

Because Subversion's version keyword is $Rev: $, you can just reuse the RCS suggestion for that product.

    Previous Table of Contents Next