B::Hooks::Parser(3pm)

✨ B::Hooks::Parser ✨

okay bestie, so this is a page from the User Contributed Perl Documentation section, and the module in question is B::Hooks::Parser πŸ’…

🌸 NAME 🌸

B::Hooks::Parser β€” your lil backstage pass to perl's parser variables πŸŽ€

πŸ’– VERSION πŸ’–

version 0.21 (yes queen, she's been around a minute)

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically this module hands you an API for parts of the perl parser πŸ‘€ and the whole point is that you can go in there and modify code while it's literally being parsed. That's right, mid-parse glow-ups only. Main character energy fr fr ✨


🧚 Perl API 🧚

setup()

Does some initialization work. πŸ’« Lowkey crucial: you must call this before any other functions of this module if you intend to use set_linestr. It returns an id, and you can use that id to disable the magic with teardown. πŸͺ„

teardown($id)

Disables the magic registered using setup. poof, no more magic ✨

get_linestr()

Returns the line the parser is currently working on πŸ‘‘ or undef if perl isn't parsing anything right now. (nothing's happening, it's giving silence 😭)

get_linestr_offset()

Returns the position within the current line to which perl has already parsed the input. If nothing is being parsed currently, you get -1. that's it, that's the vibe 🌈

set_linestr($string)

Sets the line the perl parser is currently working on to $string. iconic.

⚠️ important bestie: perl won't notice any changes in the line string after the position returned by get_linestr_offset. so anything you scribble past that point? perl is not looking. πŸ™ˆ

Also β€” it throws an exception when nothing is being compiled. πŸ’€ no compile, no dice.

inject($string)

Convenience function ✨ it inserts a piece of perl code into the current line string (as returned by get_linestr) at the current offset (as returned by get_linestr_offset). slay, little code injection πŸ’…

get_lex_stuff()

Returns the string of additional stuff resulting from recent lexing that is being held onto by the lexer. For example, the content of a quoted string goes here πŸ“. Returns "undef" if there is no such stuff.

clear_lex_stuff()

Discard the string of additional stuff resulting from recent lexing that is being held onto by the lexer. 🧹 bye bestie


🌟 C API 🌟

The following functions work just like their equivalent in the Perl API β€” except they can't handle embedded NUL bytes in strings. no NULs, we don't do that here 🚫

  • "hook_op_check_id hook_parser_setup (void)" β€” Note: may be implemented as a macro. 🫢
  • "void hook_parser_teardown (hook_op_check_id id)"
  • "const char *hook_parser_get_linestr (pTHX)"
  • "IV hook_parser_get_linestr_offset (pTHX)"
  • "void hook_parser_set_linestr (pTHX_ const char *new_value)"
  • "char *hook_parser_get_lex_stuff (pTHX)"
  • "void hook_parser_clear_lex_stuff (pTHX)"

πŸŽ€ SUPPORT πŸŽ€

Bugs may be submitted through the RT bug tracker β€” https://rt.cpan.org/Public/Dist/Display.html?Name=B-Hooks-Parser β€” or over email at bug-B-Hooks-Parser@rt.cpan.org πŸ“¬ (fr fr, they wanna hear about it)

πŸ‘‘ AUTHOR πŸ‘‘

Florian Ragwitz <rafl@debian.org>

🌈 CONTRIBUTORS 🌈

  • Karen Etheridge <ether@cpan.org>
  • Zefram <zefram@fysh.org>
  • Vincent Pit <perl@profvince.com>
  • Alexandr Ciornii <alexchorny@gmail.com>
  • Karl Williamson <khw@cpan.org>
  • Liu Kang-min <gugod@gugod.org>

(legends, every single one πŸ’œ)

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. 🩷


and that's the whole page bestie!! πŸ’– this doc was served up by perl v5.42.3, dated 2026-08-20 β€” mwah, go code, you got this πŸ¦‹βœ¨

πŸ“¦ where this page comes from