>>>>> "Mattias" == Mattias Holmlund <[EMAIL PROTECTED]> writes:

Mattias> Ok, I'll give it a shot. I experimented with how to overload
Mattias> simple_request and came up with the following. Does it seem right so
Mattias> far?

Mattias> use strict;

Mattias> use LWP::UserAgent;

Mattias> BEGIN
Mattias> {
Mattias>   print "Installing\n";
Mattias>   $LWP::Simple::FULL_LWP++;

Mattias>   my $org_simple_request = \&LWP::UserAgent::simple_request;

You need "require LWP::UserAgent" first, to ensure that this
routine has its original definition.

Mattias>   {
Mattias>     no warnings;
Mattias>     *LWP::UserAgent::simple_request = sub
Mattias>     {
Mattias>       my($self, $request, $arg, $size) = @_;
      
Mattias>       print "Overloaded\n";
Mattias>       return &$org_simple_request( $self, $request, $arg, $size );
Mattias>     }
Mattias>   }
Mattias> }
Mattias> 1;

But the rest looks fine.

The most important part here is to be conservative.  Cache only
that which is cachable, and pass everything else directly to
the original routine.  Be as thin as you can.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Reply via email to