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