ariels has asked for the wisdom of the Perl Monks concerning the following question:

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);

Replies are listed 'Best First'.
Re: Prototype weirdness in Safe
by ariels (Curate) on Jul 22, 2001 at 14:12 UTC

    Update (10:10 22 July 2001 UTC)

    It turns out that the missing opcode is gv. Changing to ...->permit_only(':base_core', 'gv') makes the prototype work.

    I still have no idea why this is, and would appreciate any enlightenment a passing wizard could cast my way.

    Also, what other (bad) things could be done with this opcode?