[Zope-Perl] Next question

Monty Taylor mtaylor@goldridge.net
Thu, 03 Aug 2000 14:04:21 +0200


This is a multi-part message in MIME format.
--------------0D7909324FFE5D403B37D7A7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Gisle Aas wrote:

> > How do I access self? (Not meta-physically, but in the sense of the
> > calling object :) )
> 
> You put the string "self" into the Arguments field.  The Arguments
> field is a comma separated list of words.  Example:
> 
>   Arguments:  self, foo, RESPONSE
> 
> will make ZPublisher call the perl method with @_ containing 3 values.
> The first and third being references to some objects, and the second
> picked up for the query string or something.

Once again, thank you. You'd think I would've picked that up from
yesterday's question. 

> > 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.
> 
> Hmm.  It works for me.  Perhaps an issue with what kind of line
> endings your browser produce.
> 

I'm using Netscape on Linux. Here's the PerlMethod text:
************
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;

#$content =~ m/^.*?<body[^>]*>//is;
#$content =~ m,</body></html>$//is;
#$content =~ m,(/comics/dilbert/archive/images/[^"]*),s;
**********
The last three comment lines and the blank line preceeding are what I've
added. Without them, it works. With them, I get the following when I hit
the 'edit' button:
Error Type: PerlError
Error Value: Missing right curly or square bracket at dilbert line 17,
at end of line syntax
          error at dilbert line 17, at EOF 

---
Wait. A-ha! If I add a blank line at the end, it works. Here's a patch
to PerlMethod that fixes it, if you want it fixed. (It's just a newline
after $code)

Thanks,
Monty
--------------0D7909324FFE5D403B37D7A7
Content-Type: text/plain; charset=us-ascii;
 name="PerlMethod.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="PerlMethod.diff"

diff -c PerlMethod.dist/__init__.py PerlMethod/__init__.py
*** PerlMethod.dist/__init__.py	Thu Aug  3 13:53:47 2000
--- PerlMethod/__init__.py	Thu Aug  3 14:01:45 2000
***************
*** 27,33 ****
                  my $name = shift || "eval";
                  my @warnings;
                  local $SIG{__WARN__} = sub { push(@warnings, @_); };
!                 $code = qq(sub {\n# line 1 "$name"\n$code });
                  my $f = eval $code;
                  if ($@) {
                      my $err = join("", $@, @warnings);
--- 27,33 ----
                  my $name = shift || "eval";
                  my @warnings;
                  local $SIG{__WARN__} = sub { push(@warnings, @_); };
!                 $code = qq(sub {\n# line 1 "$name"\n$code \n});
                  my $f = eval $code;
                  if ($@) {
                      my $err = join("", $@, @warnings);

--------------0D7909324FFE5D403B37D7A7--