Perl::Critic::Policy::Modules::ProhibitUseQuotedVersion(3pm)

Perl::Critic::Policy::Modules::ProhibitUseQuotedVersion3pm

Avoid quoted version number string in a "use" statement

Overview

This policy is part of the "Perl::Critic::Pulp" add-on. It asks you not to quote a version number string as the sole argument to a "use" or "no" statement.

    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

The unquoted form uses Perl's builtin module version check (Perl 5.004 up) and is always enforced. The quoted form is passed to the module's "import()" and relies on it to do the check. If there's no "import()" then the quoted form is silently ignored.

"Exporter" as used by many modules provides an "import()" which checks a version number arg, so those modules are fine. But the idea of this policy is to do what works always and on that basis is under the "bugs" theme (see "POLICY THEMES" in Perl::Critic).

The builtin module version check is new in Perl 5.004. For earlier versions both forms behave the same, with the string or number going through to the module "import" and so may or may not be checked. But even in code supporting older Perl it's good to write the unquoted number so later Perl will be certain to enforce it.

The policy only applies to a single number string argument, anything else is taken to be a module parameters.

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

If you're a bit nervous about unquoting because floating point version numbers are often not exactly representable in binary, well, yes, that's true, but in practice it works, either by converting the same way everywhere in the program or by treated as a string to the "version.pm" module anyway.

Disabling

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

    [-Modules::ProhibitUseQuotedVersion]

Home page

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

Releases

4 releases since Debian 10 (Buster); the text changed 1 time.

  1. 10
  2. 11–13

From libperl-critic-pulp-perl 99-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.