$VERSION diversion
frodo72
created: 2006-05-02 09:26:33
Writing a couple of scripts, I eventually got to the point to use a script-starter template much in the spirit of Module::Starter. In an effort to get things done as much cleanly as possible, I obviously included a starter boilerplate for documentation, with some basic sections like NAME, DESCRIPTION and... VERSION.

On the other hand, I also borrowed the use of the $VERSION variable from the module world:

use version; my $VERSION = qv( '0.0.1' );
Argh! Now I've to update the VERSION in two places! What's worst, this happens with modules as well, even if this kinda bothers me less because I'm not that module creator :)

Regarding scripts, I'm leaning towards eliminating the $VERSION variable, just because I seem to use it as a result of some sneaky form of cargo cult. Before I do this, anyway, I'd like to hear comments. Regarding modules, I understand the need for $VERSION, but then the double-VERSION problems strikes back.

How do you address this problem?

Flavio
perl -ple'$_=reverse' << Don't fool yourself.

Re: $VERSION diversion
created: 2006-05-02 09:51:12

I understand what you mean, it is difficult to manage the VERSION variable between multiple scripts and modules in the same distribution. Mainly because it feels like additional busy work. I do view it this way and it helps me focus on why I try to keep the version updated.

  1. Updating documentation. I will forget to update the version information in my Pod even though I updated the version for a module. It forces me to think about what I just did and go back and check my Pod for changes, not just blindly update the version everywhere. Especially when the Pod version is 1.01 and the module version 1.11. I have to think "What do I update that makes this application a more current version?"
  2. Debugging. I forget to update the version in all my modules in a distribution, I will wonder "where did this file come from? Is old or is part of the current version?" I find it is easier to update the version for all my modules in a distribution rather just update the one file that is used in Build.PL or just using dist_version parameter.
Re: $VERSION diversion
created: 2006-05-02 18:09:02

edit: this seems to work much better than my original idea:

our $VERSION;
my $version_pod = <<"=cut";
=pod

=head1 NAME

blah blah

=head1 VERSION

@{[
    $VERSION = "0.23"
]}

=cut
update: any ideas how to get the @{[]} stuff out with =for comment?

here my original idea: i found a very easy way to keep pod version numbers up-to-date. don't know if that helps in your case, but here it is:

my $version_pod = <<'=cut';
=pod

=head1 NAME

blah blah...

=head1 VERSION

our $VERSION = "0.63";

=cut

our $VERSION = "0.63";
# ...

sub __test_version {
    my $v = __PACKAGE__->VERSION;
    return 1 if $version_pod =~ m/VERSION.*\Q$v/;
    return;
}
testfile:
use Test::More tests => 2;
BEGIN { use_ok('My::Module') };
ok(My::Module->__test_version, "version ok");
as i do make test as often as possible, i never forget the version number...

still, it would be cool if you could do

our $VERSION = ($version_pod =~ m/^our \$VERSION = "(\d+(?:\.\d+)+)"/m) ? $1 : "0.01";
but doesn't work with make tardist, for example
Re: $VERSION diversion
created: 2006-07-27 05:46:06
Update: Alas, [Aristotle] [id://562735|had already written a meditation about this]!

[Aristotle] has elaborated a cool hack [http://use.perl.org/~Aristotle/journal/30358|here on use.perl.org], I hope not to infring any copyright duplicating it here:

eval "package Some::Module; $_" for grep m/ = /, split /\n/, <<'=cut';

=head1 VERSION

=for fooling makemaker
=cut-feigned

This document describes Some::Module,
$VERSION = 0.1

=cut
that yields:
$ perldoc ./Some/Module.pm | grep VERSION
       This document describes Some::Module, $VERSION = 0.1
$ perl -MSome::Module \
       -le'print Some::Module->VERSION'
0.1
$ perl -MExtUtils::MakeMaker \
       -le'print MM->parse_version(shift)' Some/Module.pm
0.1
Wow, the road to the Dark Side of the Perl is surely attractive!

Flavio
perl -ple'$_=reverse' << Don't fool yourself.

perlmonks.org content © perlmonks.org and frodo72, Herkum, tinita

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03