modperl_eval

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Subject: eval statements in mod_perl
From: "Hill, David T - Belo Corporate" <dthill@belo.com>
Date: Wed, 6 Dec 2000 10:52:53 -0600 

Howdy,
	I am running mod_perl and have created a handler that serves all the
pages for our intranet.  In this handler I load perl programs from file into
a string and run eval on the string (not in a block).  The problem is that
for any session the code doesn't work the first or second time, then it
works fine.  Is this a caching issue or compile-time vs. run-time issues?  I
am sure this is a simple fix.  What am I missing?

	Here is the nasty part (don't throw stones :)  So that we can
develop, I put the eval in a loop that tries it until it returns true or
runs 3 times.  I can't obviously leave it this way.  Any suggestions?  Here
is the relevant chunk of code:

	#  Expect perl code.  Run an eval on the code and execute it.
                        my $evalcode = "";
                        my $line = "";
                        open (EVALFILE, $build{"$nkey"});
                        while ($line = <EVALFILE>) {
                                $evalcode .= $line;
                        }
                        my $evalresult = 0;
                        my $counter=0;
 
#################################################################
                #       Temporary measure to overcome caching issue, try to
#
                #       run the eval code 3 times to get a true return.
#
 
#################################################################
                        until (($evalresult) || ($counter eq 3)) {
                                $evalresult = eval $evalcode;
                                $counter++;
                        }
                        $pageHash{"Retries"} = $counter if $counter > 1;
                        $r->print($@) if $@;
                        close (EVALFILE);

I appreciate any and all constructive comments.

===

Subject: Re: eval statements in mod_perl
From: Gunther Birznieks <gunther@extropia.com>
Date: Thu, 07 Dec 2000 16:37:35 +0800

Without knowing your whole program, this could be a variety of logic 
problems leading to this code. For example, perhaps $build{$nkey} is a 
totally bogus value the first 2 times and hence your $evalcode is also 
bogus the first two times -- and it's not a problem of eval at all!

This is unclear for the snippet.

===

Subject: RE: eval statements in mod_perl
From: "Ed Park" <epark@athenahealth.com>
Date: Thu, 7 Dec 2000 04:07:55 -0500

This was a problem that I had when I was first starting out with mod_perl;
i.e., it wouldn't work the first or second times through, and then it would
magically start working.

This was always caused for me by a syntax error in a library file. In your
case, it could be caused by a syntax error in a library file used somewhere
in your eval'd code. I highly suggest running
> perl -c <library file>
on all of your library files to check them for valid syntax. If all of your
library files are in the same directory,
> perl -c *
will work as well.

I'm not certain for the technical reason for this, but I believe it has
something to do with the fact that syntax errors in the libraries are not in
and of themselves considered a fatal condition for loading libraries in
mod_perl, so the second or third time around the persistent mod_perl process
thinks that it has successfully loaded the library. Obviously, some
functions in that library won't work, but you won't know that unless you
actually use them. Someone else might be able to shed more light on this.

===

Subject: RE: eval statements in mod_perl
From: "Hill, David T - Belo Corporate" <dthill@belo.com>
Date: Thu, 7 Dec 2000 14:13:50 -0600 

Not surprisingly, the problem turned out to be a simple one.  I was
using strict on the module that ran the eval.  The code that was being
eval'ed didn't throw an error (nothing in $@) but it did show the 
warnings in the error log.  Sorry to trouble you, and thanks for the 
responses that I did get.

===



the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu