autodie::Util(3p) Perl Programmers Reference Guide autodie::Util(3p) #
autodie::Util(3p) Perl Programmers Reference Guide autodie::Util(3p)
NNAAMMEE #
autodie::Util - Internal Utility subroutines for autodie and Fatal
SSYYNNOOPPSSIISS #
# 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"; });
DDEESSCCRRIIPPTTIIOONN #
Interal Utilities for autodie and Fatal! This module is not a part of
autodie's public API.
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".
MMeetthhooddss _o_n___e_n_d___o_f___c_o_m_p_i_l_e___s_c_o_p_e
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).
_f_i_l_l___p_r_o_t_o_s
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/[@#]_/.
_m_a_k_e___c_o_r_e___t_r_a_m_p_o_l_i_n_e
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.
_i_n_s_t_a_l_l___s_u_b_s
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 remove (possibly
"unshadowing" a CORE sub of same name).
AAUUTTHHOORR #
Copyright 2013-2014, Niels Thykier <niels@thykier.net>
LLIICCEENNSSEE #
This module is free software. You may distribute it under the same terms
as Perl itself.
perl v5.36.3 2023-02-15 autodie::Util(3p)