Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to do perl -c inside perl? (op-hook)

by tye (Cardinal)
on Aug 31, 2012 at 04:56 UTC ( #990916=note: print w/ replies, xml ) Need Help??


in reply to How to do perl -c inside perl?

I just realized that this may be quite easy to implement using existing features. Where 'this' is to run 'eval' in order to check for syntax errors while preventing any code from being run, even if a form of 'BEGIN' is used in the code.

I believe that there are ways to hook Perl's "run loop". So the steps would be:

  1. fork to get a new Perl interpreter instance (will work even on Windows)
  2. In the child instance, hook the "run loop"
  3. Call "eval $code"
  4. The run loop hook would allow Perl opnodes to execute until the 'eval' op hit
  5. If any other ops try to run after that, die
  6. CORE::exit to destroy the Perl interpreter that might have had some functions defined that we don't want to call by accident

Unfortunately, I don't know how you hook Perl's run-loop. And there might be complications to overcome when getting into the details of making this work.

But I can see real value in such a feature.

Disabling the running of code may be as simple as just defining "sub DB::sub" and "sub DB::DB" (you probably need to put your code that calls eval() into 'package DB' so it wouldn't be subject to the debugging hooks). But you can also look at what Enbugger does to enable debugging or what Devel::NYTProf does to profile opcodes.

- tye        


Comment on Re: How to do perl -c inside perl? (op-hook)
Download Code
Re^2: How to do perl -c inside perl? (op-hook)
by rockyb (Beadle) on Aug 31, 2012 at 21:21 UTC

    Something along these lines but perhaps simpler has been noted here.

    And as I commented there, I'll be experimenting with these ideas — this wasn't just idle curiosity. The very specific places I would use this are noted in 990598. I'll report back what eventually works.

    Heartfelt thanks to all who have made suggestions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990916]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2014-10-01 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (15 votes), past polls