hello
I've got a directory full of perl scripts that declare functions. These files are loaded into a Perl app-server when it starts up, but if any of the files either have compile errors, or don't end in a true value, the app server will stop but not start => stressed developers, grumpy editors.
To avoid this unhappy scenario, I wrote a simple test script that slurps each file in turn and uses a Safe to eval the code and catch errors before someone presses the big red restart button. I used Safe rather than eval because I wanted to prepare and manage the namespace in which the files are run, and protect the test's own namespace. I trust the code, um, morally, but I'm pretty suspicious of a lot of the older code's habit of stomping around in main::.
However, I'm finding what works in Safe on my own machine (Perl 5.8.0) doesn't work on the production box (5.6.0). I'm doing something like:
#!/usr/bin/perl use Safe; use Opcode; my $code; { local $/; $code = <DATA> } my $box = Safe->new(); $box->permit(Opcode::full_opset); my $return_code = $box->reval($code); __DATA__ use strict; use vars qw($foo @bar); $foo = "Friday 13th: unlucky for some";
Though this works fine in 5.8, when I run this is 5.6, it complains that '@bar requires explicit package name'. It seems that although Safe is allowing the 'use strict' declaration, it's blocking 'use vars qw(....)'.
My petition is: how can I get round this? I don't properly understand opcodes, have I done something wrong here? Or can I run this test in a different way? I'm not averse to using eval, so long as the test can control the namespace of the tested eval, and, crucially, that I don't introduce any ordering dependency into running the tests.
With thanks
ViceRaid
In reply to Strict, safely by ViceRaid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |