AUTODIE::SCOPE::GUARD(3perl)
π autodie::Scope::Guard β the vibe check π
okay bestie, welcome to the Perl Programmers Reference Guide β¨ it's giving... scope-magic. this is autodie::Scope::Guard, and i'm about to make it make sense fr fr.
πΈ NAME πΈ
autodie::Scope::Guard β a wrapper class that calls subs at end of scope. that's it, that's the whole job, and it ate π
β¨ SYNOPSIS β¨
use autodie::Scope::Guard;
$^H{'my-key'} = autodie::Scope::Guard->new(sub {
print "Hallo world\n";
});
look at that. gorgeous. no notes. π
π¦ DESCRIPTION π¦
so here's the tea, bestie β β this class is used to bless perl subs so that they get invoked when they're destroyed. the way that works is lowkey iconic: you stash an object somewhere, and when it dies, your sub runs. π
what is it actually for? mostly it's for making sure code gets invoked at end of scope. periodt. π
β οΈ important: this module is not a part of autodie's public API. so like, don't go building your whole personality around it, okay? π
also, full credit where credit is due: this module is directly inspired by chocolateboy's excellent Scope::Guard module π absolute legend behavior.
π§ Methods π§
π new
my $hook = autodie::Scope::Guard->new(sub {});
creates a new autodie::Scope::Guard, which will invoke the given sub once it goes out of scope β i.e. its DESTROY handler is called. main character energy honestly π
π AUTHOR π
Copyright 2008-2009, Paul Fenwick <pjf@perltraining.com.au>
^(shoutout to Paul, we stan π«Ά)
π LICENSE π
This module is free software. You may distribute it under the same terms as Perl itself. πΈ
π and that's the whole page, bestie. slay. no cap.
signing off with the deets: this was perl v5.44.0, dated 2026-10-17, from the autodi...::Guard(3perl) page. iykyk β¨π¦ππ
π¦ 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