autouse(3perl)

✨ NAME ✨

autouse β€” bestie, it literally postpones the load of modules until a function is actually used πŸ’… no cap


πŸŽ€ SYNOPSIS πŸŽ€

use autouse 'Carp' => qw(carp croak);
carp "this carp was predeclared and autoused ";

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the vibe. If the module Module is already loaded, then this declaration:

use autouse 'Module' => qw(func1 func2($;$));

is equivalent to this:

use Module qw(func1 func2);

...as long as Module defines func2() with the prototype ($;$), and func1() has no prototypes. (And at least if Module uses Exporter's import β€” otherwise it's a fatal error, bestie, no take-backs. πŸ’€)

But if the module Module is not loaded yet, then that same declaration declares func1() and func2() in the current package. When those functions get called, they load the package Module if needed, and then substitute themselves with the correct definitions. It's giving glow-up mid-runtime, honestly. ✨


πŸ’€ WARNING πŸ’€

Not me about to tell you the scary part. Using autouse will move important steps of your program's execution from compile time to runtime. This can:

  • Break the execution of your program if the module you autoused has some initialization which it expects to be done early. 😭
  • Hide bugs in your code since important checks (like correctness of prototypes) is moved from compile time to runtime. In particular, if the prototype you specified on the autouse line is wrong, you will not find it out until the corresponding function is executed. This will be very unfortunate for functions which are not always called (note that for such functions autouseing gives biggest win, for a workaround see below). πŸ™ˆ

To alleviate the second problem (partially) it is advised to write your scripts like this:

use Module;
use autouse Module => qw(carp($) croak(&$));
carp "this carp was predeclared and autoused ";

The first line ensures that the errors in your argument specification are found early. πŸ‘‘ When you ship your application you should comment out the first line, since it makes the second one useless. periodt.


πŸ’– AUTHOR πŸ’–

Ilya Zakharevich (ilya@math.ohio-state.edu)


🌸 SEE ALSO 🌸

perl(1).


okay that's the whole page, you ate it up fr fr 🫢 this was perl v5.44.0, dated 2026-10-17 β€” and yes, it's still autouse(3perl) in the Perl Programmers Reference Guide, slay πŸ’…πŸŒˆ

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND 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