autodie::Util(3perl)

๐Ÿ’– autodie::Util โ€” bestie edition ๐Ÿ’–

So this is autodie::Util, part of the Perl Programmers Reference Guide, and it's the little internal toolbox that keeps autodie and Fatal ticking. ๐ŸŽ€


โœจ NAME โœจ

autodie::Util โ€” Internal Utility subroutines for autodie and Fatal ๐Ÿ› ๏ธ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

# INTERNAL API for autodie and Fatal only!

use autodie::Util qw(on_end_of_compile_scope);
on_end_of_compile_scope(sub { print "Hallo world\n"; });

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so Internal Utilities for autodie and Fatal! This module is not a part of autodie's public API, bestie. It's the backstage area. ๐Ÿ‘‘

This module contains utility subroutines for abstracting away the underlying magic of autodie and (ab)uses of "%^H" to call subs at the end of a (compile-time) scopes.

Note that due to how "%^H" works, some of these utilities are only useful during the compilation phase of a perl module and relies on the internals of how perl handles references in "%^H". ๐Ÿ’… iykyk


๐Ÿ”ฅ Methods ๐Ÿ”ฅ

โญ on_end_of_compile_scope

on_end_of_compile_scope(sub { print "Hallo world\n"; });

Will invoke a sub at the end of a (compile-time) scope. The sub is called once with no arguments. Can be called multiple times (even in the same "compile-time" scope) to install multiple subs. Subs are called in a "first-in-last-out"-order (FILO or "stack"-order). ๐Ÿฅžโœจ

โญ fill_protos

fill_protos('*$$;$@')

Given a Perl subroutine prototype, return a list of invocation specifications. Each specification is a listref, where the first member is the (minimum) number of arguments for this invocation specification. The remaining arguments are a string representation of how to pass the arguments correctly to a sub with the given prototype, when called with the given number of arguments. ๐Ÿงฎ

The specifications are returned in increasing order of arguments starting at 0 (e.g. ';$') or 1 (e.g. '$@'). Note that if the prototype is "slurpy" (e.g. ends with a "@"), the number of arguments for the last specification is a "minimum" number rather than an exact number. This can be detected by the last member of the last specification matching m/[@#]_/. ๐Ÿ‘€

โญ make_core_trampoline

make_core_trampoline('CORE::open', 'main', prototype('CORE::open'))

Creates a trampoline for calling a core sub. Essentially, a tiny sub that figures out how we should be calling our core sub, puts in the arguments in the right way, and bounces our control over to it. ๐Ÿคธโ™€๏ธโœจ

If we could reliably use `goto &` on core builtins, we wouldn't need this subroutine. ๐Ÿ’€

โญ install_subs

install_subs('My::Module', { 'read' => sub { die("Hallo\n"), ... }})

Given a package name and a hashref mapping names to a subroutine reference (or "undef"), this subroutine will install said subroutines on their given name in that module. If a name mapes to "undef", any subroutine with that name in the target module will be removed (possibly "unshadowing" a CORE sub of same name). ๐Ÿซถ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Copyright 2013-2014, Niels Thykier <niels@thykier.net> ๐Ÿ’œ


๐ŸŒˆ LICENSE ๐ŸŒˆ

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


and that's the whole vibe check, bestie โ€” this page is from perl v5.44.0, dated 2026-10-17 (autodie::Util(3perl)). slay, go forth and compile ๐Ÿ’–โœจ๐Ÿฆ‹

๐Ÿ“ฆ 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