I've been playing around with Safe, but I've hit a problem with @ISA / inheritance, and I can't seem to work round it. I managed to strip everything right back to a very small example which shows the problem.
#! /usr/bin/perl -w
use strict;
use Safe;
my $CODE = << 'END';
package A;
sub new {
my($class) = @_;
bless { }, $class;
}
package B;
our @ISA = qw(A);
END
# If I uncomment this line, everything works.
# eval $CODE;
my $safe = Safe->new();
$safe->reval($CODE);
warn "code - $@" if $@;
$safe->reval("B->new();");
warn "new - $@" if $@;
When I run this, I get "Can't locate package A for @B::ISA" (twice). If I uncomment the eval, then the problem goes away - but of course in the real app, I don't want to eval the untrusted code outside of Safe (so just suggesting that I uncomment it, isn't going to help me much :-)
Can someone explain to me what's going on? Any idea how I might get round this problem?
Have fun,
rdw
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, 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, 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.
|
|