I’m working on a bot in Perl (based on POE) and so far so good, but I can’t figure out how can I add a !js or !perl command to evaluate respective code and return one line of output to be printed into the channel. I found App::EvalServer but I don’t get how to use it.
Thanks for any help!
The
App::EvalServermodule comes with a binary to run as a standalone application. You do not put it in your program but rather run it on it’s own. It opens a port where you can hand it code as a json string. This does not sound like a good idea to me either.There is another module you might want to look at called Safe. I suggest you read through the complete documentation as well as the one to Opcode (linked in the doc) before you do anything with this. YOU CAN DO SERIOUS DAMAGE IF YOU EVALUATE ARBITRARY CODE! Never forget that.
UPDATE:
Here’s an example of how to capture the output of
printorsayfrom yourevaled code. You can useopenwith a variable to makeprinted output always go to that variable. If you switch back afterwards you can work with the captured output in your var. This is called an in-memory file.Disclaimer: Use this code at your own risk!
Update 2: After a lengthy discussion in chat, here’s what we came up with. It implements a kind of timeout to stop the execution if the
revalis taking to long, e.g. because of an infinite loop.