Perl::...erSubs(3pm)

πŸ“¦
version 0.08 Β· 2 versions
, in fedora 43

πŸ’– NAME πŸ’–

Perl::Critic::StricterSubs β€” it's a Perl::Critic plugin that does stricter subroutine checks, and honestly? It's giving safety rails. Periodt.


✨ AFFILIATION ✨

Okay so real talk: this module has no functionality whatsoever. Zero. It's literally just documentation for this whole distribution, plus it acts as a way to pull the other modules into one bundle. Every single Policy module in here will have its own "AFFILIATION" section announcing that it's part of this little squad. 🫢


🌸 DESCRIPTION 🌸

So here's the tea, bestie. Perl is a dynamic language, which means it does not make you define your subroutines until run-time. That's a powerful feature, sure, but it is also a major source of bugs. Like, imagine: you mistype a subroutine name. Or you call a sub from another module without actually including that module or importing that sub. And unless your test coverage is genuinely iconic, you might not find out about these bugs until your code is already out in the world. 😭

The Perl::Critic::Policy modules in this distribution are all about reducing the errors you get from invoking subroutines that aren't defined. Each Policy works fine on its own, but when you run them together, they enforce one specific, deliberate coding style that minimizes your chances of writing code that calls undefined subs.

Now β€” this coding style is not for everyone, and that's okay! Some folks will definitely find it too verbose or too restrictive. Specifically: importing via Exporter tags and pattern matching is purposely not supported. But hopefully these Policies get you to consciously consider the inherent trade-offs of whatever coding style you're rocking right now. ✨


πŸ’€ LIMITATIONS πŸ’€

Perl::Critic is a static analyzer, so the Policies in this distro only deal with static subroutines. Y'know, calls that typically look like one of these:

  foo();
  Bar::baz( $string );
  Quux->new( @args );

At present, Perl::Critic can't know the class ancestry of any particular object reference. So the Policies in this distro do not cover object methods, like these:

  $object->foo();

Also, it's genuinely hard for Perl::Critic to know precisely which static subroutines will actually be defined at run time. So yeah β€” these Policies are expected to report some false violations. πŸ™ˆ Which means you probably do not want to use them with Test::Perl::Critic or any other framework that expects 100% violation-free code. Instead, the suggestion here is to use these Policies with the perlcritic command to do ad hoc analysis of your code.

Heads up: false positives are baked in. Don't let a strict CI setup gaslight you into thinking your code is broken. πŸ’…

πŸ‘‘ INCLUDED POLICIES πŸ‘‘

The following Policy modules ship in this distribution. Peep the docs inside each module for the details on its specific behavior.

🌈 Perl::Critic::Policy::Modules::RequireExplicitInclusion

If you refer to symbols in another package, you must explicitly include that module. [Severity: 4]

🌈 Perl::Critic::Policy::Subroutines::ProhibitCallsToUndeclaredSubs

Unqualified subroutines must always be declared or explicitly imported within the file. [Severity: 4]

🌈 Perl::Critic::Policy::Subroutines::ProhibitCallsToUnexportedSubs

Only allow calls to external subroutines that are named in @EXPORT or @EXPORT_OK. [Severity: 4]

🌈 Perl::Critic::Policy::Subroutines::ProhibitExportingUndeclaredSubs

All subroutines named for @EXPORT or @EXPORT_OK must be defined in the file. [Severity: 4]

🌈 Perl::Critic::Policy::Subroutines::ProhibitQualifiedSubDeclarations

Do not declare subroutines with fully-qualified names [Severity: 3]


πŸŽ€ CONFIGURATION πŸŽ€

Once you install the Perl-Critic-StricterSubs distro, all the included Policies are available to the Perl::Critic engine. Every Policy in this distro belongs to the strictersubs theme, so you can disable all of them at once using either of these methods:

  # In your .perlcriticrc file...
  theme = not strictersubs

  # With the perlcritic command-line...
  $> perlcritic --theme='not stricter_subs' MyModule.pm

See "CONFIGURATION" in Perl::Critic section for more info about configuring the Perl::Critic engine. πŸ’œ

Each Policy in this distro may support extra configuration settings that you can reach through your .perlcriticrc file. Check the perldoc in each Policy for more deets.


πŸ¦‹ ACKNOWLEDGEMENTS πŸ¦‹

DEVELOPMENT of the Perl-Critic-StricterSubs distribution was financed by a grant from The Mathworks (<http://mathworks.com>). The Perl::Critic team sincerely thanks The Mathworks for their generous support of the Perl community and open-source software. 🫢 That's genuinely so sweet of them, no cap.


πŸ“ AUTHOR πŸ“

Jeffrey Ryan Thalhammer <thaljef@cpan.org>


Copyright 2007-2024 Jeffrey Ryan Thalhammer and Andy Lester

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 thing, bestie! πŸ’… This was perl v5.42.0, dated 2025-07-25, from your friends over at Perl::...erSubs(3pm) in the User Contributed Perl Documentation. Slay, go write some declared subroutines. πŸ‘‘βœ¨

πŸ“¦ where this page comes from