summaryrefslogtreecommitdiff
path: root/regen
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 /regen
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 'regen')
-rw-r--r--regen/mg_vtable.pl11
1 files changed, 11 insertions, 0 deletions
diff --git a/regen/mg_vtable.pl b/regen/mg_vtable.pl
index debe6bf066..5c8a37c15f 100644
--- a/regen/mg_vtable.pl
+++ b/regen/mg_vtable.pl
@@ -168,10 +168,17 @@ my %mg =
desc => 'Tied scalar or handle' },
qr => { char => 'r', vtable => 'regexp', value_magic => 1,
readonly_acceptable => 1, desc => 'Precompiled qr// regex' },
+
+ hook => { char => 'Z',
+ vtable => 'hook', desc => '%{^HOOK} hash' },
+ hookelem => { char => 'z',
+ vtable => 'hookelem', desc => '%{^HOOK} hash element' },
+
sig => { char => 'S', vtable => 'sig',
desc => '%SIG hash' },
sigelem => { char => 's', vtable => 'sigelem',
desc => '%SIG hash element' },
+
taint => { char => 't', vtable => 'taint', value_magic => 1,
desc => 'Taintedness' },
uvar => { char => 'U', vtable => 'uvar',
@@ -262,6 +269,10 @@ my %vtable_conf =
'sig' => { set => 'setsigall' },
'sigelem' => {get => 'getsig', set => 'setsig', clear => 'clearsig',
cond => '#ifndef PERL_MICRO'},
+
+ 'hook' => { set => 'sethookall', clear => 'clearhookall' },
+ 'hookelem' => {set => 'sethook', clear => 'clearhook'},
+
'pack' => {len => 'sizepack', clear => 'wipepack'},
'packelem' => {get => 'getpack', set => 'setpack', clear => 'clearpack'},
'dbline' => {set => 'setdbline'},