[Zope-Perl] Next question

Monty Taylor mtaylor@goldridge.net
Thu, 03 Aug 2000 10:38:37 +0200


Hey Gisle,

Here's the next question...

How do I access self? (Not meta-physically, but in the sense of the
calling object :) ) 
I'm trying to get at the RESPONSE object to set some headers. Any ideas?

Also, comments don't seem to work so well in PerlMethods. I commented
out some lines and then got syntax errors. I took out the comment lines
and all was good again.

I have succeeded in using LWP::UserAgent to serve third-party content
from Zope... mirroring the How-To of the same nature that tells you how
to use ZPublisher.Client. As far as I could tell, though,
ZPublisher.Client didn't have proxy or cookie handling support. Anyway,
for what it's worth, here's the code I knocked up to do it.

DTMLDocument: dilbert.gif
  Properties: content_type=image/gif
  Content:
<dtml-var dilbert>

PerlMethod: dilbert
  Content:
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new('GET','http://www.dilbert.com');
$ua->proxy(['http','ftp'], 'http://192.168.131.1:8080');
my $response = $ua->request($request);
my $content = $response->content;
$content =~ m,(/comics/dilbert/archive/images/[^"]*),s;
my $img = HTTP::Request->new('GET',"http://www.dilbert.com/$1");
my $img_response = $ua->request($img);
$content = $img_response->content;
return $content;

Then, for fun, I added:
<img src="dilbert.gif></img> 
to my standard_html_footer.
Works like a charm!

Thanks,
Monty