http://www.perlmonks.org?node_id=127011


in reply to How to use LWP::Simpe inside a safe compartment?

First of all let me say that I know nothing about how Safe.pm works. However, I was able to run your program without errors with the following change:
$codefromoutside='print wget "http://google.com";'; use LWP::Simple (); sub wget { LWP::Simple::get $_[0] } use Safe; $safe=new Safe; $safe->share(qw(LWP::Simple::get)); ## <- note change here $safe->reval($codefromoutside); print $@ if $@;
This may be inappropriate or not, I don't know, but maybe it helps.

--Jim

Replies are listed 'Best First'.
Re: Re: How to use LWP::Simpe inside a safe compartment?
by Anonymous Monk on Dec 07, 2001 at 05:23 UTC
    Hi Jim...

    Thanks for your try, but I didn't get any result with this code either. What should happen is that "googe.com" should be downloaded and printed out...

    I tried:

    $safe->share(qw(LWP::Simple::get wget));
    but it gives
    require trapped by operation mask at C:/Perl/5.00503/lib/IO/Socket.pm +line 9.
    which means that LWP::Simple::get tries to load some stuff which is forbidden within the safe compartment.

    Nobody any further ideas!?

    Best regards,

    Christoph Bergmann

      Take a look at http://perldoc.perl.org/Safe.html. You probably want to do a safe->permit('require').

      I can't say that it will make your program work, but it will get you past that particular error.