develooper Front page | perl.perl5.changes | Postings from March 2023

[Perl/perl5] b978ff: regen/mg_vtable.pl - rename confusing var %sigto ...

From:
Yves Orton via perl5-changes
Date:
March 10, 2023 19:49
Subject:
[Perl/perl5] b978ff: regen/mg_vtable.pl - rename confusing var %sigto ...
Message ID:
Perl/perl5/push/refs/heads/yves/require_hook_rebased/2a5426-0ef4ff@github.com
  Branch: refs/heads/yves/require_hook_rebased
  Home:   https://github.com/Perl/perl5
  Commit: b978ffe262bbd2b7c26861bc26ff2785ce632600
      https://github.com/Perl/perl5/commit/b978ffe262bbd2b7c26861bc26ff2785ce632600
  Author: Yves Orton <demerphq@gmail.com>
  Date:   2023-03-10 (Fri, 10 Mar 2023)

  Changed paths:
    M regen/mg_vtable.pl

  Log Message:
  -----------
  regen/mg_vtable.pl - rename confusing var %sig to %vtable_conf


  Commit: 0ef4ffa5a4bdc54a0d2d2740edb724a1e9bcff9b
      https://github.com/Perl/perl5/commit/0ef4ffa5a4bdc54a0d2d2740edb724a1e9bcff9b
  Author: Yves Orton <demerphq@gmail.com>
  Date:   2023-03-10 (Fri, 10 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
    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 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/2a54265c990e...0ef4ffa5a4bd



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About