summaryrefslogtreecommitdiff
path: root/mg_names.inc
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-12-19 19:32:03 +0100
committerYves Orton <demerphq@gmail.com>2023-03-18 20:57:59 +0800
commit93f6f9654a81b66c47c07ca982e4c00558bd4159 (patch)
treeeb352f43ebad63b8813f6b3ef7b2084fd91df13f /mg_names.inc
parent2f920c2f73ae58b754ccf1d897f1104e0cc3a4c6 (diff)
downloadperl-93f6f9654a81b66c47c07ca982e4c00558bd4159.tar.gz
pp_ctl.c - add support for hooking require.
This defines a new magic hash C<%{^HOOK}> which is intended to be used for hooking keywords. It is similar to %SIG in that the values it contains are validated on set, and it is not allowed to store something in C<%{^HOOK}> that isn't supposed to be there. Hooks are expected to be coderefs (people can use currying if they really want to put an object in there, the API is deliberately simple.) The C<%{^HOOK}> hash is documented to have keys of the form "${keyword}__${phase}" where $phase is either "before" or "after" and in this initial release two hooks are supported, "require__before" and "require__after": The C<require__before> hook is called before require is executed, including any @INC hooks that might be fired. It is called with the path of the file being required, just as would be stored in %INC. The hook may alter the filename by writing to $_[0] and it may return a coderef to be executed *after* the require has completed, otherwise the return is ignored. This coderef is also called with the path of the file which was required, and it will be called regardless as to whether the require (or its dependencies) die during execution. This mechanism makes it trivial and safe to share state between the initial hook and the coderef it returns. The C<require__after> hook is similar to the C<require__before> hook however except that it is called after the require completes (successfully or not), and its return is ignored always.
Diffstat (limited to 'mg_names.inc')
-rw-r--r--mg_names.inc2
1 files changed, 2 insertions, 0 deletions
diff --git a/mg_names.inc b/mg_names.inc
index e46c71faf6..29338448ce 100644
--- a/mg_names.inc
+++ b/mg_names.inc
@@ -48,6 +48,8 @@
{ PERL_MAGIC_substr, "substr(x)" },
{ PERL_MAGIC_nonelem, "nonelem(Y)" },
{ PERL_MAGIC_defelem, "defelem(y)" },
+ { PERL_MAGIC_hook, "hook(Z)" },
+ { PERL_MAGIC_hookelem, "hookelem(z)" },
{ PERL_MAGIC_lvref, "lvref(\\)" },
{ PERL_MAGIC_checkcall, "checkcall(])" },
{ PERL_MAGIC_extvalue, "extvalue(^)" },