B::Hook...OfScope(3)

okay bestie, welcome to the B::Hooks::EndOfScope(3) page from the User Contributed Perl Documentation β€” the header truncates the name a little, but we're here and we're gonna make it make sense πŸ’…βœ¨

🌸 NAME 🌸

B::Hooks::EndOfScope β€” execute code after a scope finished compilation. That's the iconique one-line summary, no cap. πŸ‘‘

πŸ’– VERSION πŸ’–

version 0.28 β€” that's the version, bestie.

✨ SYNOPSIS ✨

    on_scope_end { ... };

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this module lets you execute code when perl finished compiling the surrounding scope. Literally that's the vibe: perl finishes compiling the scope around you, then your callback gets to run. 🫢

πŸŽ€ FUNCTIONS πŸŽ€

πŸ’… on_scope_end πŸ’…

    on_scope_end { ... };

    on_scope_end $code;

on_scope_end registers $code to be executed after the surrounding scope has been compiled. It's exported by default β€” slay. If you wanna customize the export, see Sub::Exporter; that's where the customization tea is. 🍡

😭 LIMITATIONS 😭

🫧 Pure-perl mode caveat 🫧

this caveat applies to any version of perl where Variable::Magic is unavailable or otherwise disabled. okay so Variable::Magic has access to some very dark sorcery that makes it possible to throw an exception from within a callback, but the pure-perl implementation does not have access to these hacks. So what would have been a compile-time exception gets converted into a warning instead, and your execution continues as if the exception never happened. 😭

To explicitly request an XS (or PP) implementation, you have two choices. Either import from the desired implementation explicitly:

        use B::Hooks::EndOfScope::XS
          or
        use B::Hooks::EndOfScope::PP

or set $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION} to either "XS" or "PP".

🐚 Perl 5.8.0 ~ 5.8.3 🐚

Because of a core interpreter bug β€” https://rt.perl.org/Public/Bug/Display.html?id=27040#txn-82797 β€” present in older perl versions, the implementation of B::Hooks::EndOfScope deliberately leaks a single empty hash for every scope being cleaned. That's on purpose, bestie, to avoid the memory corruption associated with the bug mentioned above. πŸ’€

In order to stabilize this workaround, use of Variable::Magic is disabled on perls prior to version 5.8.4. On such systems, loading/requesting B::Hooks::EndOfScope::XS explicitly will result in a compile-time exception. periodt.

🧚 Perl versions 5.6.x 🧚

Versions of perl before 5.8.0 lack a feature allowing changing the visibility of %^H via setting bit 17 within $^H. So the only way to achieve the effect necessary for this module to work is to use the local operator explicitly on these platforms. That might lead to unexpected interference with other scope-driven libraries relying on the same mechanism. On the flip side, there are no such known incompatibilities at the time this note was written. 🌈

For further details on the unavailable behavior, please refer to the test file t/02-localise.t included with the distribution.

πŸ‘€ SEE ALSO πŸ‘€

  • Sub::Exporter
  • Variable::Magic

🫢 SUPPORT 🫢

Bugs may be submitted through the RT bug tracker https://rt.cpan.org/Public/Dist/Display.html?Name=B-Hooks-EndOfScope (or bug-B-Hooks-EndOfScope@rt.cpan.org, shown in the original as <mailto:bug-B-Hooks-EndOfScope@rt.cpan.org>).

πŸ‘‘ AUTHORS πŸ‘‘

  • Florian Ragwitz <rafl@debian.org>
  • Peter Rabbitson <ribasushi@leporine.io>

🌟 CONTRIBUTORS 🌟

  • Karen Etheridge <ether@cpan.org>
  • Graham Knop <haarg@haarg.org>
  • Christian Walde <walde.christian@googlemail.com>
  • Simon Wilper <sxw@chronowerks.de>
  • Tatsuhiko Miyagawa <miyagawa@bulknews.net>
  • Tomas Doran <bobtfish@bobtfish.net>

This software is copyright (c) 2008 by Florian Ragwitz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


okay bye bestie! this page came from perl v5.42.0, dated 2024-03-01, and it's the B::Hook...OfScope(3) manual β€” xoxo, go compile something cute πŸ’–βœ¨

πŸ“¦ where this page comes from