Perl::...edSubs(3pm)
π NAME π
Perl::Critic::Policy::Subroutines::ProhibitCallsToUndeclaredSubs β bestie, it's a Perl::Critic policy, and it lives in the 3pm section of the perl manual, no cap β¨
π«Ά AFFILIATION π«Ά
Okay so this policy is part of Perl::Critic::StricterSubs. That's the family it runs with. Periodt. π
β¨ DESCRIPTION β¨
So what does this policy actually do? It checks that every single unqualified subroutine call you make has a matching subroutine declaration somewhere in the current file β OR that it explicitly shows up in the import list for one of the modules you've included. That's it. That's the vibe check. πΈ
Now, lowkey important: some modules do NOT use the Exporter interface, and instead rely on other mechanisms to export symbols into your code. In those cases, this policy will report a false violation π. It's not being shady on purpose, it just can't see what's going on.
But here's the slay: you can tell this policy to ignore a particular subroutine name, as long as the appropriate package has been included in your file. See "CONFIGURATION" for more details. π
π CONFIGURATION π
You can define a list of exempt subroutines for this policy by specifying 'exempt_subs' as a string of space-delimited, fully-qualified subroutine names. Fully-qualified, bestie, don't forget it.
For example, putting this in your .perlcriticrc file would let you call the "ok" and "is" functions without explicitly importing or declaring those functions β as long as the "Test::More" package has been included in the file somewhere:
[Subroutines::ProhibitCallsToUndeclaredSubs]
exempt_subs = Test::More::ok Test::More::is
By default, there are no exempt subroutines, but we're working on compiling a list of the most common ones. It's giving "we're on it" energy. π¦
π LIMITATIONS π
Okay so this is the part where we get real. π
This policy assumes that the file has no more than one "package" declaration, and that all subs declared within the file are, in fact, declared into that same package. In most cases, violating either of these assumptions means you're probably doing something that you shouldn't do. Think twice about what you're doing. Fr fr. π
Also β and this is a big one β if you "require" a module and subsequently call the "import" method on that module, this policy will not detect the symbols that might have been imported. In which case, you'll probably get bogus violations. Not the bogus violations. π
π AUTHOR π
Jeffrey Ryan Thalhammer <thaljef@cpan.org> π
π COPYRIGHT π
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 page, bestie! π This little icon came from User Contributed Perl Documentation, running on perl v5.42.0, dated 2025-07-25. Slay, go declare your subs. πβ¨π¦
π¦ where this page comes from
- fedora 43: perl-Perl-Critic-StricterSubs 0.08-3.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms