I've come across a weirdness in using
Safe with just the
:base_core ops, using Perl 5.005_03. I have a
sub foo with a
prototype of `
()' (takes no args), which I can use by calling just
foo. But doing so in a Safe compartment with the
reval method fails; I
have to add brackets, or I get "
glob value trapped by operation mask". Calling with brackets works, though.
Using the :default opset works. Which op do I need to add to :base_code to allow prototype lookup to work?
The enclosed code demonstrates:
#!/usr/local/bin/perl -w
use strict;
use Safe;
# Stuff from here will be shared into the Safe compartment
package Shared;
{
my $n;
sub foo() { ++$n };
}
package main;
my $cpt = new Safe;
$cpt->permit_only(':base_core');
$cpt->share_from( Shared => [qw( &foo )] );
print "foo returns ", Shared::foo, "\n"
for (1..3);
sub safe_eval {
my $q = shift;
my $res = $cpt->reval($q);
if ($@) {
"ERROR: $@\n";
}
else {
"$res\n";
}
}
print "reval(foo) returns ", safe_eval('foo') for (1..3);
print "reval(foo()) returns ", safe_eval('foo()') for (1..3);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.