http://www.perlmonks.org?node_id=11123913

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

I am trying to incorporate version numbers into modules that will only be used internally and cannot get it to work. As a basic testcase, I have the following file Foo.pm, located at '/home/user/perl_modules/lib/perl5/My/Foo.pm':

package Foo; our $VERSION = '1.0'; use strict; use warnings; sub new { my $class = shift(); my ($arguments) = @_; my $self = {}; bless $self, $class; }

I also have the following script, foo_version_test.pl, used to test the version number of Foo.pm:

#!/tool/bin/perl -w use strict; use lib '/home/user/perl_modules/lib/perl5'; use My::Foo 1.0; printf("version = %s\n", $Foo::VERSION);

Running the script produces the following output:

My::Foo defines neither package nor VERSION--version check failed at . +/foo_version_test.pl line 4. BEGIN failed--compilation aborted at ./foo_version_test.pl line 4.

I'm not sure what's going wrong here given that both the package and VERSION statements exist in Foo.pm.

On a related note, if I have modules that will only be used internally and that I want to version (as opposed to modules I download from CPAN, in which subsequent module updates overwrite the previous module version), suppose I have the following directory structure:

/home/user/perl_modules/lib/perl5/My/FooVersion 1.0/ Foo.pm 1.1/ Foo.pm 1.2/ Foo.pm Devel/ Foo.pm

How would I use a particular version of Foo.pm in my script? Perl is fine with:

use My::FooVersion::Devel::Foo;

but trying to reference any of the numbered versions in the same manner, even when I quote either the numerical portion or the entire string, produces syntax errors. For example, none of the following work:

use My::FooVersion::1.1::Foo; use "My::FooVersion::1.1::Foo"; use My::FooVersion::"1.1"::Foo; use My::FooVersion::'1.1'::Foo; use 'My::FooVersion::1.1::Foo';