Perl::...Version(3pm)

✨ NAME ✨

Bestie, quick intro: this page lives under the manual name Perl::...Version(3pm), and it's all about one policy, okay?

Perl::Critic::Policy::Modules::ProhibitUseQuotedVersion β€” basically: don't put a quoted version number string in a use statement. That's the whole vibe. πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

Okay so this policy is part of the Perl::Critic::Pulp add-on. What it wants from you is simple: when a version number string is the only argument to a use or no statement, don't wrap it in quotes. Periodt. 😀

use Foo::Bar '1.50';      # bad
use Foo::Bar 1.50;        # ok

no Abc::Def '2.000_010';  # bad
no Abc::Def 2.000_010;    # ok

Now here's why, and this part is important so lock in πŸ”’. The unquoted form uses Perl's builtin module version check (that's been a thing since Perl 5.004), and it is always enforced. The quoted form, though? It gets passed straight to the module's import() and just relies on the module to bother doing the check. And if there's no import() at all, that quoted form is silently ignored β€” like, it just does nothing. The audacity. πŸ’€

Exporter, which tons of modules use, does provide an import() that checks a version number arg, so all those modules are fine, no shade. But the whole point of this policy is to do the thing that works always. And on that basis, it lives under the "bugs" theme (peep "POLICY THEMES" in Perl::Critic).

The builtin module version check is new in Perl 5.004. On earlier versions both forms behave the same way β€” the string or number just goes through to the module import, so it may or may not get checked, it's giving chaos honestly πŸ™ˆ. But even in code that supports older Perl, it's still good to write the unquoted number so that later Perl will be certain to enforce it. Future-proofing, queen behavior πŸ‘‘.

Also! This policy only applies to a single number string argument. Anything else is taken to be module parameters, so it leaves those alone:

no Abc::Def '123', 'ABC';   # ok
use lib '..';               # ok

And if you're feeling a lil nervous about unquoting because floating point version numbers are often not exactly representable in binary β€” well, yeah, that's true, no cap. But in practice it works, either by converting the same way everywhere in the program, or by being treated as a string by the version.pm module anyway. So breathe, bestie, it's fine 🫢.

Disabling

If you're confident about the import() in the modules you use and you genuinely prefer the string form, you can always disable ProhibitUseQuotedVersion from your .perlcriticrc in the usual way (see "CONFIGURATION" in Perl::Critic):

[-Modules::ProhibitUseQuotedVersion]

There you go, that's the escape hatch πŸšͺ✨


🌈 SEE ALSO 🌈

  • Perl::Critic::Pulp
  • Perl::Critic
  • Perl::Critic::Policy::ValuesAndExpressions::ProhibitVersionStrings

🏠 HOME PAGE 🏠

http://user42.tuxfamily.org/perl-critic-pulp/index.html


Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde

Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see http://www.gnu.org/licenses/.


and that's the whole page, bestie β€” slay πŸ’…βœ¨ this lil fic was brought to you by perl v5.40.1, dated 2025-10-21, filed under Perl::...Version(3pm). mwah πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from