Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

$VERSION Archeology

by bsb (Priest)
on Jul 08, 2008 at 13:42 UTC ( #696215=perlmeditation: print w/replies, xml ) Need Help??

I and others have asked about $VERSION numbers and updating them automatically. After noticing YAWTDI, I decided to investigate the different $VERSION styles found in the wild (where "in the wild" means on a machine of mine).
# get the versions in context locate .pm | grep 'pm$' | xargs | xargs grep -C2 '$VERSION.*=' > versi +ons-C2 # find the interesting versions perl -nle 'if(/\.pm:(.*)/){s/\d/1/g;print}' versions-C2 | sort -u | le +ss # find the popular versions (w/ roughly canonical lines) perl -nle 'if(/\$VERSION.*=/) { s/.*\.pm://; s/\s+/ /g; s/\d+/1/g; pri +nt }' \ versions-C2 | sort | uniq -c | sort -rn | head -n 10 | nl
The top ten (semi-canonical form) from a total of 4707.
1 1892 $VERSION = "1.1"; 2 916 our $VERSION = "1.1"; 3 247 $VERSION = 1.1; 4 243 our $VERSION = 1.1; 5 194 use SVK::Version; our $VERSION = $SVK::VERSION; 6 113 $VERSION = eval $VERSION; 7 87 our $VERSION = do{my@r=(q$Revision:1.1$=~/\d+/g);sprintf"%d.". +"%1d"x$#r,@r}; 8 67 $VERSION = sprintf("%d.%02d", q$Revision:1.1$ =~ /(\d+)\.(\d+) +/); 9 56 $VERSION = "1.02_01"; 10 51 ($VERSION) = sprintf '%i.%03i', split(/\./, \# break for pm.or +g ("$Revision: 2.6$"=~/Revision:(\S+)\s/)[1]); #$Date: 2007/05/07 20 +:33:46 $

The first caveat is that there's a lot of "unique" lines with comments. Another caveat is that there may be build systems filling in $VERSION before deployment. Finally, there are some exotic forms (package vars and glob assignments) not included.

The longest line was in Perl/ (excluding the comments)
( $VERSION = q($Id:,v 1.64 2007/05/08 20:01:45 perltidy Exp $) + ) =~ s/^.*\s+(\d+)\/(\d+)\/(\d+).*$/$1$2$3/; # all one line for Make +Maker

A few observations. The basic $VERSION = "1.01" is the most popular by far. There's still many keyword expanded $Revision$s parsed into a $VERSION (158). About the same number append $Revision$, $Id$ or $Date$ in a comment.

Despite it's presence in Module/Starter/ (twice), qv() versions haven't really taken off (use version; $VERSION = qv('0.0.3')). Similarly, bare \d.\d.\d versions are rare, as are fully-qualified package versions, glob assignments and "alpha" suffixes.

Performing the ExtUtils::MakeMaker eval reveals that the most common version is 0.01. The most common format is \d.\d\d (3025), next is \d.\d\d\d (433), then v\d.\d.\d (216).

I quite like the SVK solution for app-wide versions:

# SVK::* modules: use SVK::Version; our $VERSION = $SVK::VERSION; # In SVK::Version itself: use version; our $VERSION = qv(2.0.2);

Although the possibility of arbitrary code running on a version evaluation is a little troubling.

Some other interesting versions are:
# 2005.082401 $VERSION = 2005.0824_01; # 5.402212 $VERSION = sprintf "%.6f", substr(q$Rev: 2212 $,4)/1000000 + 5.4; $VERSION = (qw$LastChangedRevision: 388 $)[1]; # 12.009530 $VERSION = sprintf("12.%06d", q$Id: 9530 2007-05-09 13:05:23Z t +imbo $ =~ /(\d+)/o); $VERSION = 1.19_01; # ^ ^^ ^^-- Incremented at will # | \+----- Incremented for non-trivial changes to features # \-------- Incremented for fundamental changes
Some modules wrap the $VERSION assignment in either a BEGIN or (as we do) a use param:
use Our::Config ( application => 'app-name', version => (our $VERSION = '3.1'), config => \$config, );
Any I've missed in my sample?

Replies are listed 'Best First'.
Re: $VERSION Archeology
by brian_d_foy (Abbot) on Jul 08, 2008 at 15:06 UTC
      I see this handles pod correctly. That tripped up my scripts.

      I think the "without running code" might be better written as "without running the entire module", since there's still a string eval (if I understand the code correctly).

Re: $VERSION Archeology
by Herkum (Parson) on Jul 08, 2008 at 20:44 UTC

    I tried using the version module. It was a pain in the a** for something that was doing something so simple. It was just easier to hand code a version and be done with it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://696215]
Approved by Tanktalus
[stevieb]: I don't even own a Windows computer. Both my girl and I have a laptop each with Linux. I'm supporting Windows in some of my projects and I can't even guage whether it's worth it or not.
[stevieb]: shmem It's something I desired to have years ago, which is why I took over berrybrew. Cross-platform build/test automation locally, or over the network Test::BrewBuild
[shmem]: sounds good.
[shmem]: but I'm crumbling smaller stones. remember...
[stevieb]: I'm working on it to fatten it up and make it more reliant so I can finalize my Raspberry Pi automated build system for that software :) It's all well and fun, until I try to make it work with Windows lol
[shmem]: "debugging a program is more difficult than to write it in the first place. If you code your program as smart as you are, you are, by definition, too dumb to debug it."

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2017-03-28 22:10 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (342 votes). Check out past polls.