diff options
author | Yves Orton <demerphq@gmail.com> | 2022-12-19 19:32:03 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-03-18 20:57:59 +0800 |
commit | 93f6f9654a81b66c47c07ca982e4c00558bd4159 (patch) | |
tree | eb352f43ebad63b8813f6b3ef7b2084fd91df13f /regcomp_internal.h | |
parent | 2f920c2f73ae58b754ccf1d897f1104e0cc3a4c6 (diff) | |
download | perl-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 'regcomp_internal.h')
0 files changed, 0 insertions, 0 deletions