Hi monks,
I am given a code string by user, and wants to know if the code contains statements or special blocks that are executed not in regular run time. For example:
use Foo "bar"; bar(); # yes bar(); baz() if $qux; # no bar(); END { warn "qux" } # yes
The reason is because I need to eval the code string and later dump the code back to string. And these statements/blocks do not get included. Demonstration:
% perl -MData::Dumper -E'$Data::Dumper::Deparse=1; print Dumper(eval q +[sub {use File::chdir; local $CWD="/"; END { warn } }])' $VAR1 = sub { use feature 'current_sub', 'bitwise', 'evalbytes', 'fc', ' +postderef_qq', 'say', 'state', 'switch', 'unicode_strings', 'unicode_ +eval'; local $CWD = '/'; }; Warning: something's wrong at (eval 5) line 1.
I want to be able to warn the user when her code contains these things. I'm thinking of PPI right now, but that seems too heavy. Ideas on other ways to do this?
In reply to Knowing when a code string contains code that will be executed at compile-time/end? by perlancar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |