Perl::...edSubs(3pm)

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

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