Is there a way to access special tokens in perl from XS?

前端 未结 3 962
一个人的身影
一个人的身影 2021-01-04 10:25

In perl special tokens like __PACKAGE__, __SUB__, __FILE__, __LINE__ exists and available from script.

I may get

3条回答
  •  独厮守ぢ
    2021-01-04 11:17

    You can look them up one by one in toke.c for the compile-time values:

    • __PACKAGE__ => HvNAME(PL_curstash) or PL_curstname
    • __FILE__ => CopFILE(PL_curcop) (at compile-time)
    • __LINE__ => CopLINE(PL_curcop) (at compile-time)
    • __SUB__ => PL_compcv

    If you need them at run-time look at the various data fields available in the context caller_cx and current sub (cv). There's no context struct as in parrot or perl6 passed around, rather a stack of active context blocks.

提交回复
热议问题