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::StricterSubs
  • strict

go read them, bestie, they're the extended universe. 🌈


🫢 AUTHOR 🫢

Andrew Main (Zefram) <zefram@fysh.org> β€” thank you for your service, king πŸ‘‘


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