autodi...dStack(3perl)

πŸ’– autodi...dStack(3perl) β€” the hook stack that runs your cleanup at the exact right moment πŸ’–

okay bestie, sit down, because this little page lives in the Perl Programmers Reference Guide and it is so niche and so good. if you've ever wondered how a pragma politely un-installs stuff when it goes out of scope, this is the ✨ machinery ✨. let's go πŸ¦‹


🌸 NAME 🌸

autodie::Scope::GuardStack β€” Hook stack for managing scopes via %^H πŸ’…

like. it's a stack. of hooks. that live in %^H. that's the whole vibe.


✨ SYNOPSIS ✨

use autodie::Scope::GuardStack;
my $stack = autodie::Scope::GuardStack->new
$^H{'my-key'} = $stack;

$stack->push_hook(sub {});

the way you make one, shove it into %^H under your own key, and then yeet hooks at it. iconic behavior honestly πŸŽ€

(and yes, the ->new line above really does have no semicolon in the original. not me fixing it. not my job. iykyk 😭)


πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the tea πŸ“: this class is a stack of hooks β€” little subs β€” and it calls them in the right order as scopes go away. the stack is only useful when you insert it into %^H, and it will pop hooks as their "scope" gets popped. that's lowkey the entire point: it's for uninstalling or reinstalling subs in a namespace as a pragma goes out of scope. main character energy for cleanup code πŸ’…

⚠️ now the part where you pay attention: because of how %^H works, this class is only useful during the compilation phase of a perl module, and it relies on perl's internals for how references are handled in %^H. also β€” and this is important, bestie β€” this module is not a part of autodie's public API. it's the private backstage area. no cap. 🫢

🧚 Methods 🧚

⭐ new

my $stack = autodie::Scope::GuardStack->new;

creates a new autodie::Scope::GuardStack. ✨

the stack starts out empty β€” like, totally empty, no hooks, nothing β€” and the creator (that's you, babe) has to insert it into %^H themselves. it does not do that part for you πŸ™ˆ

⭐ push_hook

$stack->push_hook(sub {});

adds a sub to the stack. πŸ’–

that sub will get called once the current compile-time "scope" is left. and yes, you can add multiple hooks per scope β€” stack them up, bestie, they're all getting called. slay. πŸ”₯


🌈 AUTHOR 🌈

Copyright 2013, Niels Thykier <niels@thykier.net>


πŸ’œ LICENSE πŸ’œ

This module is free software. You may distribute it under the same terms as Perl itself.


okay that's the whole page, you ate it, you understood it, periodt πŸ’…βœ¨

this was perl v5.44.0, dated 2026-10-17, and you just read the autodi...dStack(3perl) page. go be a legend with your hook stack, bestie πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ 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