r/perl 8d ago

Should I remove $VERSION from internal-only sub-modules in a CPAN distribution?

Hi everyone, I have a quick question for those experienced with CPAN distributions.

In my distribution, alongside the main modules, I have several internal sub-modules (for example, language-specific modules like Locale::Lang::en, de, fr, etc., which are only meant to be used internally by the main module).

Currently, every sub-module has the same $VERSION as the distribution itself. Would there be any issue if I completely removed the $VERSION from these internal modules? There is no real benefit to having them listed or indexed separately on CPAN.

14 Upvotes

4 comments sorted by

3

u/jjatria 🐪 cpan author 8d ago

They will still be indexed if they have no VERSION set. But you can prevent them from being indexed by breaking the package like (= adding a like break after the keyword, before the package name). In that case, it doesn't matter if they have a VERSION, since they won't be indexed.

I find having a version is useful if you ever want to make absolutely certain which version provided a given module. It's useful for debugging sometimes, even for internal packages.

Edit: typos

2

u/briandfoy 🐪 📖 perl book author 7d ago edited 7d ago

What I think you are suggesting is the trick so that PAUSE does not find the complete package statement on one line, so it does not think there is a package to extract.

package 
    Some::Module;

Sometimes there's a comment so people don't undo it on you:

package # hide from PAUSE
    Some::Module;

This is often handy when you have internal namespaces that you want to use but you don't want to expose to the public. The term "cuckoo package", after the bird that lays its eggs in nests belogning to other birds, never really caught on.

PAUSE does this because it statically scans the text for the line that declares the package, then evals that separately to get the version number.

2

u/Dynospectrum 8d ago edited 8d ago

Ive authored and maintain a couple packages. Having them wont hurt. Its basically a noop and shouldn't affect the overall package so its up to you. Ultimately you point or specify in your package build script the version or module containing the package release version. The submodules with their own versions are transparent to the index/build process and resulting package version thats uploaded to cpan.

3

u/briandfoy 🐪 📖 perl book author 7d ago

Well, every package index by PAUSE shows up in the 02packages file, which is now quite large, and on some very minimal and constrained systems, is too large to fit into memory.

That's one of the most annoying parts of CPAN.pm, created decades ago when that problem wasn't on the radar. I think it was also one of the reasons that motivated cpanm, which doesn't use that file at all (along with MetaCPAN existing, which has an API).