Safe Module Question 
Author Message
 Safe Module Question

I have a quick question about the Perl Safe module.

 I have a function which is called from a safe compartment successfully.
 However the function contains the following:

 use LWP::UserAgent;
 use HTTP::Request::Common;

 sub getURL {

 my $url = shift;

  my $useragent = new LWP::UserAgent;

 [snip]

 This causes an error :

 Can't locate object method "new" via package "LWP::UserAgent" at
 safe_test.pl line 13.

 The code works fine if 'evaled'. I know there must be a simple
solution but
 just can't see it.

Thanks,
--
Michael Holligan

website: web4test.com

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 23 Feb 2003 17:00:57 GMT  
 Safe Module Question

Quote:

> I have a quick question about the Perl Safe module.

>  I have a function which is called from a safe compartment successfully.
>  However the function contains the following:

>  use LWP::UserAgent;
>  use HTTP::Request::Common;

>  sub getURL {

>  my $url = shift;

>   my $useragent = new LWP::UserAgent;

>  [snip]

>  This causes an error :

>  Can't locate object method "new" via package "LWP::UserAgent" at
>  safe_test.pl line 13.

>  The code works fine if 'evaled'. I know there must be a simple solution but
>  just can't see it.

This is your classic Safe problem. Because a "new" changes the symbol
table to add methods, it will always fail.

The solution is to create the object beforehand.

  use LWP::UserAgent;
  use HTTP::Request::Common;

  my $useragent = new LWP::UserAgent;

  sub getURL {

  my $url = shift;

   $useragent->do_something_with($url);
   ....
 }

This gets complicated, and doesn't cover many aspects of objects.
You can also Safe::Hole to wrap an object method; it works.

--
Akopia, Inc., 131 Willow Lane, Floor 2, Oxford, OH  45056

Fast, reliable, cheap.  Pick two and we'll talk.  -- unknown



Sun, 23 Feb 2003 21:39:14 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Safe Module Question

2. DBI Syntax

3. How safe is Safe?

4. I wrote Safe::Hole which makes Safe more useful

5. POSIX in Safe compartments (was: Q: Safe...)

6. Safe.pm and making eval safe

7. How to use modules inside a safe compartment?

8. Thread safe modules

9. Safe module and %SIG problem

10. Using Safe with modules

11. Help with Safe module and safecgiperl

12. Using Perl Safe module?

 

 
Powered by phpBB® Forum Software