in reply to help with versioning modules
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.pmHow 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';
use expect a bareword, not a string. Period. If you want module names that are not barewords, you are already begging for trouble, as package expects a namespace, not a string.
Anyway, it is possible to load a module from such "unperlish" names. This is slightly hidden in use:
Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to
BEGIN { require Module; Module->import( LIST ); }except that Module must be a bareword.
require allows to use a bareword, but you can alternatively provide a filename to be loaded. To generate a filename from a bareword, convert all :: and ' to / and append .pm.
I think the idea to load several versions of the same module into the same namespace is really, really begging for trouble.
There may be reasons for having versioned module name spaces, for example to support APIs or protocols with different versions. Consider an imaginary set of HTTP protocol modules:
Note that version numbers were changed to allow their use in barewords. Also note that those modules would load into different namespaces.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: help with versioning modules
by Special_K (Pilgrim) on Nov 23, 2020 at 01:25 UTC |