Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by Anonymous Monk
on Nov 22, 2001 at 20:04 UTC ( #126978=perlquestion: print w/replies, xml ) Need Help??

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


I want to use LWP::Simple inside a safe compartment created with the Safe Module. But it ends up with errors like "Can't locate object method "new" via package "LWP::UserAgent" at line... or "Require trapped by operation mask..."

Here is how the code looks like (shortened ;-) ):

$codefromoutside='print wget "";'; use LWP::Simple (); sub wget { LWP::Simple::get $_[0] } use Safe; $safe=new Safe; $safe->share(qw(wget)); $safe->reval($codefromoutside); print $@ if $@;
(There is a reason why I use "wget" instead of "get" directly because I have already a subroutine with the name "get" elsewhere)

I tried some other things but they all didn't work. Does anybody know how to use LWP::Simple::get inside a save compartment?

Thanks in advance,

best regards,

Christoph Bergmann

Replies are listed 'Best First'.
Re: How to use LWP::Simpe inside a safe compartment?
by jlongino (Parson) on Nov 23, 2001 at 00:18 UTC
    First of all let me say that I know nothing about how works. However, I was able to run your program without errors with the following change:
    $codefromoutside='print wget "";'; 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.


      Hi Jim...

      Thanks for your try, but I didn't get any result with this code either. What should happen is that "" 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/ +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 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://126978]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2021-06-23 12:16 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (119 votes). Check out past polls.