B::Hook...hChange(3)
β¨ NAME β¨
B::Hooks::OP::Check::StashChange β bestie, this is a Perl module that invokes callbacks when the stash code is being compiled in changes π (yes that's the whole pitch, and it's iconic). It lives in section 3 of the manual, under User Contributed Perl Documentation, so you know it's a real one π
πΈ SYNOPSIS πΈ
From Perl πͺ
package Foo;
use B::Hooks::OP::Check::StashChange;
our $id = B::Hooks::OP::Check::StashChange::register(sub {
my ($new, $old) = @_;
warn "${old} -> ${new}";
});
package Bar; # "Foo -> Bar"
B::Hooks::OP::Check::StashChange::unregister($Foo::id);
package Moo; # callback not invoked
From C/XS π
#include "hooks_op_check_stashchange.h"
STATIC OP *
my_callback (pTHX_ OP *op, char *new_stash, char *old_stash, void *user_data) {
/* ... */
return op;
}
UV id;
/* register callback */
id = hook_op_check_stashchange (cv, my_callback, NULL);
/* unregister */
hook_op_check_stashchange_remove (id);
π¦ DESCRIPTION π¦
Okay so there's two ways to play this game β the Perl way and the C/XS way. Both are valid, both are giving β¨
π Perl API
π register
B::Hooks::OP::Check::
# or
my $id = B::Hooks::OP::Check::StashChange::register(\&callback);
Register callback when an opcode is being compiled in a different namespace than the previous one. That's it, that's the moment it fires π₯
An id gets returned to you, and you can use that id later to remove the handler with unregister. Keep it safe, bestie, you'll want it back π
π unregister
B::Hooks::OP::Check::StashChange::unregister($id);
Disable the callback referenced by $id. Bye bye callback, you were lowkey doing great π
π C API
π TYPES
OP *(*hook_op_check_stashchange_cb) (pTHX_ OP *op, const char
*new_stash, const char *old_stash, void *user_data)
This is the type your callbacks need to implement. No substitutions, no vibes-based reinterpretations, implement this exact one π
π§ FUNCTIONS
UV hook_op_check_stashchange (hook_op_check_stashchange_cb cb, void *user_data)
Register the callback cb to be when an opcode is compiled in a different namespace than the previous. user_data will be passed to the callback as the last argument. π«Ά
It returns an id that you can use to remove the handler using hook_op_check_stashchange_remove. Screenshot the id, write it down, put it in a notes app β whatever, just don't lose it β¨
void *hook_op_check_stashchange_remove (UV id)
Remove a previously registered handler referred to by id. π (in the nice way)
It returns the user data that was associated with the handler. So you get your stuff back, periodt.
π SEE ALSO π
B::Hooks::OP::Checkβ go look at that one too, iykyk π
π AUTHOR π
Florian Ragwitz <rafl@debian.org> β the main character who made all of this happen π
π COPYRIGHT AND LICENSE π
Copyright (c) 2008 Florian Ragwitz
This module is free software.
You may distribute this code under the same terms as Perl itself. Slay.
Okay bestie that's the whole page, every option, every id, every const, nothing skipped, no cap π
This was perl v5.42.0, dated 2025-07-25, straight from B::Hook...hChange(3) in the User Contributed Perl Documentation β love u, go compile something cute π
π¦
π¦ where this page comes from
- fedora 43: perl-B-Hooks-OP-Check-StashChange 0.06-51.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms