---
name: "B::Hooks::Parser"
section: "3pm"
platform: "linux"
package: "libb-hooks-parser-perl"
version: "0.21-3+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/B::Hooks::Parser"
---

# B::Hooks::Parser(3pm)

Interface to perl's parser variables

## NAME

B::Hooks::Parser - Interface to perl's parser variables

## VERSION

version 0.21

## DESCRIPTION

This module provides an API for parts of the perl parser. It can be used to modify code while it's being parsed.

## Perl API

### setup()

Does some initialization work. This must be called before any other functions of this module if you intend to use `"set_linestr"`. Returns an id that can be used to disable the magic using `"teardown"`.

### teardown($id)

Disables magic registered using `"setup"`.

### get\_linestr()

Returns the line the parser is currently working on, or undef if perl isn't parsing anything right now.

### get\_linestr\_offset()

Returns the position within the current line to which perl has already parsed the input, or -1 if nothing is being parsed currently.

### set\_linestr($string)

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

Note that perl won't notice any changes in the line string after the position returned by `"get_linestr_offset"`.

Throws an exception when nothing is being compiled.

### inject($string)

Convenience function to insert 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"`).

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

## C API

The following functions work just like their equivalent in the Perl API, except that they can't handle embedded `"NUL"` bytes in strings.

### "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 bug-B-Hooks-Parser@rt.cpan.org \<mailto:bug-B-Hooks-Parser@rt.cpan.org\>).

## 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\>

## COPYRIGHT AND LICENCE

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.
