Perl::...ionVar(3pm)

✨ Perl::Critic::Policy::Modules::RequireVersionVar(3pm) ✨

okay bestie, so this is a page from the User Contributed Perl Documentation (the 3pm manual section, iykyk) and it's literally all about making sure every single module has a $VERSION. Yes, every one. No skipping. πŸ’…


πŸŽ€ NAME πŸŽ€

Perl::Critic::Policy::Modules::RequireVersionVar β€” give every module a $VERSION number. that's it. that's the whole vibe. πŸ‘‘


🌸 AFFILIATION 🌸

so this Policy is part of the core Perl::Critic distribution. it's not some random add-on, it comes with the crew. 🫢


πŸ’– DESCRIPTION πŸ’–

Every Perl file β€” and yes, that means modules, libraries, and programs β€” should have a package-scoped $VERSION variable. like, all of them. no exceptions, bestie.

and why, you ask? because $VERSION is what lets clients insist on a particular revision of your file, like this:

use SomeModule 2.4;  #Only loads version 2.4

okay so this Policy scans your file for any package variable named $VERSION. it's assuming you're using strict (as you should, icon behaviour), so you'll have to declare it like one of these:

our $VERSION = 1.0611;
$MyPackage::VERSION = 1.061;
use vars qw($VERSION);
use version; our $VERSION = qv(1.0611);

any of those four? slay. you're valid. βœ…

⚠️ but here's the thing β€” Perl's version system does not recognize lexical variables like my $VERSION = 1.0611; so those are not accepted by this policy. sad but true. 😭

a common practice (and honestly kind of iconic) is to use the $Revision$ keyword to automatically define the $VERSION variable like this:

our ($VERSION) = '$Revision$' =~ m{ \$Revision: \s+ (\S+) }x;

πŸ¦‹ CONFIGURATION πŸ¦‹

This Policy is not configurable except for the standard options. that's right, there's nothing to tweak here. it is what it is. πŸ€·β€β™€οΈ


🧚 NOTES 🧚

Conway recommends using the version pragma instead of raw numbers or 'v-strings.' (very "listen to your elders" of him tbh). However, this Policy only insists that the $VERSION be defined somehow. the author may try to extend this in the future β€” so like, watch this space. πŸ‘€


πŸ”₯ TO DO πŸ”₯

  • Add check that $VERSION is independently evaluatable. in particular, prohibit this:
our $VERSION = $Other::Module::VERSION;

and why doesn't that work? because PAUSE and other tools literally copy your version declaration out of your module and evaluate it in isolation, at which point there's nothing in Other::Module β€” and so the $VERSION is undefined. πŸ’€ so yeah, don't do that.


🌈 AUTHOR 🌈

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>


Copyright (c) 2005-2021 Imaginative Software Systems. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.


and that's the whole page, bestie! ✨ this was perl v5.42.0, dated 2024-10-23 β€” go forth and version your modules, fr fr. πŸ“πŸ’œ

πŸ“¦ where this page comes from