Branch: refs/heads/yves/require_hook_rebased Home: https://github.com/Perl/perl5 Commit: 00852b4105b731ffbcbf89578d587635bf88d782 https://github.com/Perl/perl5/commit/00852b4105b731ffbcbf89578d587635bf88d782 Author: Yves Orton <demerphq@gmail.com> Date: 2023-03-16 (Thu, 16 Mar 2023) Changed paths: M embed.fnc M embed.h M proto.h M sv.h M sv_inline.h Log Message: ----------- sv.h - add SvREFCNT_dec_set_NULL() and also SvREFCNT_dec_ret_NULL() which is used to implement SvREFCNT_dec_set_NULL(). The set_NULL() macro is intended to be used to replace code like this: if (sv) { SvREFCNT_dec_NN(sv); sv = NULL; } The function form just facilitates it, and can be used in situations where returning NULL after decrementing a refcount would be reduce code complexity. Commit: 3dcd4b2a986921f438f55774bb61329ecfa332b9 https://github.com/Perl/perl5/commit/3dcd4b2a986921f438f55774bb61329ecfa332b9 Author: Yves Orton <demerphq@gmail.com> Date: 2023-03-16 (Thu, 16 Mar 2023) Changed paths: M MANIFEST M embed.fnc M embed.h M embedvar.h M gv.c M intrpvar.h M mg.c M mg_names.inc M mg_raw.h M mg_vtable.h M perl.c M pod/perldiag.pod M pod/perlfunc.pod M pod/perlguts.pod M pod/perlvar.pod M pp_ctl.c M proto.h M regen/mg_vtable.pl M sv.c M t/harness A t/lib/caller/Bicycle.pm A t/lib/caller/Cycle.pm A t/lib/caller/Tricycle.pm M t/op/glob.t A t/op/hook/require.t Log Message: ----------- 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. Compare: https://github.com/Perl/perl5/compare/20423f8df1ec...3dcd4b2a9869