Home > Archive > PERL Miscellaneous > May 2006 > safe-module and namespaces
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
safe-module and namespaces
|
|
| peter pilsl 2006-05-31, 8:05 am |
|
I try to use the safe-module to evaluate user-provided code, but it
seems there is a knot in my brain.
use Safe;
$s=new Safe "xxx";
$xxx::x=3;
$s->reval('$x=4');
print $xxx::x,"\n"
Well, this prints out 3 as result and I think it should be 4!
What am I not thinking of?
thnx,
peter
| |
| Brian McCauley 2006-05-31, 7:06 pm |
| peter pilsl wrote:
> I try to use the safe-module to evaluate user-provided code, but it
> seems there is a knot in my brain.
>
> use Safe;
> $s=new Safe "xxx";
> $xxx::x=3;
> $s->reval('$x=4');
> print $xxx::x,"\n"
>
>
> Well, this prints out 3 as result and I think it should be 4!
Works OK for me (i.e. prints 4) with Perl 5.8.7 and Safe 2.11
| |
| Charles DeRykus 2006-05-31, 7:06 pm |
| peter pilsl wrote:
>
> I try to use the safe-module to evaluate user-provided code, but it
> seems there is a knot in my brain.
>
> use Safe;
> $s=new Safe "xxx";
> $xxx::x=3;
> $s->reval('$x=4');
> print $xxx::x,"\n"
>
>
> Well, this prints out 3 as result and I think it should be 4!
> What am I not thinking of?
>
I don't know Safe well... ok, hardly at all.
But, I suspect package variables seen outside the safe
compartment are no longer accessible. I'm not sure how
the mechanism works to ensure that.
If 'xxx' is explicitly shared, the following does print '4'.
my $s = Safe->new( "xxx" );
$xxx::x=3;
$s->share_from('xxx', ['$x'] );
$s->reval('$x=4');
print $xxx::x;
--
Charles DeRykus
| |
| Charles DeRykus 2006-05-31, 7:06 pm |
| Brian McCauley wrote:
> peter pilsl wrote:
>
>
> Works OK for me (i.e. prints 4) with Perl 5.8.7 and Safe 2.11
>
Odd, I could've sworn I duplicated Peter's results but I confirmed
it works on 5.6.1 and Safe 2.06 as well as 5.8.8 and Safe 2.12 too.
So, forget my earlier suggestion to explicitly share 'xxx'...
--
Charles DeRykus
|
|
|
|
|