Sub::StrictDecl(3pm)
π Sub::StrictDecl π
okay bestie, so this is the User Contributed Perl Documentation page for Sub::StrictDecl(3pm), and it is literally about catching undeclared subroutines while the thing is still compiling. no cap, your typos get found before runtime even has a chance to embarrass you. periodt.
β¨ NAME β¨
Sub::StrictDecl β detect undeclared subroutines in compilation π΅οΈβοΈ
πΈ SYNOPSIS πΈ
use Sub::StrictDecl;
no Sub::StrictDecl;
it's giving two lines of pure power fr fr.
π¦ DESCRIPTION π¦
So here's the vibe: this module gives you optional checking of whether a subroutine actually exists, and it does it at compile time. We're talking mistyped subroutine names getting caught, and subroutines that the programmer (respectfully, we've all been there π) forgot to import. Traditionally Perl does not detect these errors until runtime, which means it's so easy for errors to be lurking in the rarely-executed or untested code. like, hiding. waiting. π
Specifically β and this is the important bit β where checking is enabled, any reference to a specific (compile-time-constant) package-based subroutine name gets examined. If the named subroutine has never been declared, then an error is signalled at compile time. π₯
And no, the sub doesn't have to be fully defined for this to work: a forward declaration like sub foo; is enough to suppress the error. imported subroutines qualify as declared too, obviously. π
References that get checked are not only subroutine calls β they also include pure referencing, like \&foo. yes bestie, even the quiet ones. π
This checking is controlled by a lexically-scoped pragma. Which means it only applies to code that explicitly wants the checking, and you can locally disable it if you need to. Iconic behaviour, honestly.
β οΈ heads up: checking might need to be turned off for code that makes special arrangements to put a subroutine in place at runtime. iykyk. π§
π PACKAGE METHODS π
Sub::StrictDecl->importβ turns on subroutine declaration checking in the lexical environment that is currently compiling. slay πSub::StrictDecl->unimportβ turns off subroutine declaration checking in the lexical environment that is currently compiling. bye boo π
π SEE ALSO π
Perl::Critic::StricterSubsstrict
go read them, bestie, they're the extended universe. π
π«Ά AUTHOR π«Ά
Andrew Main (Zefram) <zefram@fysh.org> β thank you for your service, king π
π COPYRIGHT π
Copyright (C) 2011 PhotoBox Ltd
Copyright (C) 2011, 2015, 2017 Andrew Main (Zefram) <zefram@fysh.org>
β LICENSE β
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie!! π this one came from the perl v5.42.3 manual pages, dated 2026-08-22, and it lives under Sub::StrictDecl(3pm). go forth and declare your subs. π¦β¨
π¦ where this page comes from
- ubuntu stonking: libsub-strictdecl-perl 0.005-2build7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms