Perl::...ersion(3pm)

okay so bestie πŸ’– welcome to the Perl::Critic::Policy::ValuesAndExpressions::ProhibitComplexVersion manual page β€” yep, the one whose header gets squished down to Perl::...ersion(3pm) β€” brought to you by User Contributed Perl Documentation. grab a strawberry πŸ“ and let’s get into it.

🌸 NAME 🌸

Perl::Critic::Policy::ValuesAndExpressions::ProhibitComplexVersion β€” Prohibit version values from outside the module.

πŸŽ€ AFFILIATION πŸŽ€

This Policy is part of the core Perl::Critic distribution. iconic behavior, honestly πŸ‘‘.

✨ DESCRIPTION ✨

okay so here’s the tempting idea: keep a whole group of related modules at the same version number by having all of them import the version number from one designated module. for example, module Foo::Master could be the version master for the Foo package, and all the other modules could use its $VERSION like this:

use Foo::Master; our $VERSION = $Foo::Master::VERSION;

and ngl, this turns out not to be a good idea 😭. all sorts of unintended things can happen β€” anything from unintended version number changes to denial-of-service attacks (since Foo::Master is executed by the 'use').

this policy examines statements that assign to $VERSION, and it declares a violation under two circumstances:

  • first, if that statement uses a fully-qualified symbol that did not originate in a package declared in the file;
  • second, if there is a use statement on the same line that makes the assignment.

by default, an exception is made for use version; because of its recommendation by Perl Best Practices. see the forbid_use_version configuration variable if you do not want an exception made for use version;. πŸ’…

πŸ› οΈ CONFIGURATION πŸ› οΈ

the construction

use version; our $VERSION = qv('1.2.3');

is exempt from this policy by default, because it is recommended by Perl Best Practices. should you wish to identify use version; as a violation, add the following to your perlcriticrc file:

[ValuesAndExpressions::ProhibitComplexVersion]
forbid_use_version = 1

slay, that’s the whole config vibe πŸŽ€βœ¨

πŸ’€ CAVEATS πŸ’€

this code assumes that the hallmark of a violation is a 'use' on the same line as the $VERSION assignment, because that is the way to have it seen by ExtUtils::MakeMaker->parse_version(). other ways to get a version value from outside the module can be imagined, and this policy is currently oblivious to them. no cap, that’s the caveat 🫢.

🌈 AUTHOR 🌈

Thomas R. Wyant, III wyant at cpan dot org

Copyright (c) 2009-2023 Tom Wyant

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. periodt πŸ’…


this page was served fresh from perl v5.42.0 on 2024-10-23 πŸŽ€βœ¨

πŸ“¦ where this page comes from