/home/user/perl_modules/lib/perl5/My/Foo.pm:foo_version_test.pl:package Foo; our $VERSION = '1.0'; use strict; use warnings; sub new { my $class = shift(); my ($arguments) = @_; my $self = {}; bless $self, $class; }#!/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);
Filename and package name do not match.
If the file name (relative to the include path) is My::Foo, and you load the module in foo_version_test.pl by use My::Foo, then the package name should be My::Foo, not Foo. Loading the module creates a global variable named $Foo::VERSION, but use My::Foo 1.0 tests for a variable named $My::Foo::VERSION.
It is perfectly legal to have package names in a module that to not match the file name, so perl does not warn. But it causes a lot of trouble (see Breaking Tie::Hash into three modules for an example). As a rule of thumb, make sure that package names and file names match.
Update: Modern versions of perl also allow package My::Foo 1.0;, implicitly setting $My::Foo::VERSION and matching use My::Foo 1.0. See also package.
Alexander
In reply to Re: help with versioning modules
by afoken
in thread help with versioning modules
by Special_K
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |