B::Hook...hChange(3)

πŸ“¦
version 0.06 Β· 2 versions
, in fedora 43

✨ 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 (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