Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use B::Hooks to manipulate the perl parser

Tags:

perl

xs

I'm looking to play with perl parser manipulation. It looks like the various B::Hooks modules are what people use. I was wondering:

  1. Best place to start for someone who has no XS experience (yet). Any relevant blog posts?

  2. How much work would be involved in creating a new operator, for example:

    $a~>one~>two~>three

~> would work like -> but it would not try to call on undef and would instead simply return undef to LHS.

Although a source filter would work -- I'm more interested in seeing how you can manipulate the parser at a deeper level.

like image 608
LLFourn Avatar asked May 23 '15 15:05

LLFourn


1 Answers

I don't believe you can add infix operators (operators whose operands are before and after the operator), much less symbolic ones (as opposed to named operators), but you could write an an op checker that replaces method calls. This means you could cause ->foo to behave differently. By writing your module as a pragma, you could limit the effect of your module to a lexical scope (e.g. { use mypragma; ...}).

like image 127
ikegami Avatar answered Nov 08 '22 11:11

ikegami