autodie::Util(3pm)
π autodie::Util β like, the internal utility subs for autodie and Fatal
okay so real talk: this page is autodie::Util(3pm) from the Perl Programmers Reference Guide, and it's the backstage-crew module nobody's supposed to see. π
β¨ 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 β¨
Internal Utilities for autodie and Fatal! π Say it with me: this module is not a part of autodie's public API. It's giving "staff only, bestie" energy. πͺ
What lives in here is a lil pile of utility subroutines that abstract away the underlying magic of autodie and the (very much *ab*uses) of "%^H" to call subs at the end of a (compile-time) scope. πͺ
Heads up, and this is important: because of how"%^H"works, some of these utilities are only useful during the compilation phase of a perl module, and they rely on the internals of how perl handles references in"%^H". So likeβ¦ don't come for me if you use them at runtime. π
πΈ 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 gets called once, with no arguments. You can call this multiple times β even inside the same "compile-time" scope β to install multiple subs. And the subs fire in a "first-in-last-out"-order (FILO, aka "stack"-order). Stack behavior, iconic behavior. ππ
fill_protos
fill_protos('*$$;$@')
Give it a Perl subroutine prototype and it hands back a list of invocation specifications. π₯ Each specification is a listref where:
- the first member is the (minimum) number of arguments for that invocation specification, and
- the remaining members are a string representation of how to pass the arguments correctly to a sub with the given prototype, when it's called with that given number of arguments.
The specifications come back in increasing order of arguments, starting at 0 (like ';$') or 1 (like '$@'). π
Careful tho: if the prototype is "slurpy" (like, ends with an'@'), then the number of arguments for the last specification is a "minimum" number, not an exact one. You can detect this by checking whether the last member of the last specification matchesm/[@#]_/. π΅οΈββοΈ
make_core_trampoline
make_core_trampoline('CORE::open', 'main', prototype('CORE::open'))
Creates a trampoline for calling a core sub. πͺ Essentially it's a tiny sub that figures out how we should be calling our core sub, puts the arguments in the right way, and bounces our control over to it. Bounce, bounce, slay. π¦
If we could reliably use `goto &` on core builtins, we wouldn't need this subroutine. But we can't, so here we are. π
install_subs
install_subs('My::Module', { 'read' => sub { die("Hallo\n"), ... }})
Give it a package name and a hashref mapping names to a subroutine reference (or "undef"), and this subroutine will install said subroutines under their given name in that module. π οΈ And if a name maps to "undef", then any subroutine with that name in the target module gets removed β which possibly "unshadows" a CORE sub of the 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. π«Ά Legal but make it cute.
and that's the whole page, bestie!! π this was autodie::Util(3pm) β perl v5.42.3, dated 2026-11-03, brought to you by the Perl Programmers Reference Guide. mwah, go compile something β¨ππ
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms