You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by do...@hyperreal.org on 1998/05/15 01:30:08 UTC

cvs commit: modperl-site/dist mod_perl_traps.html

dougm       98/05/14 16:30:07

  Modified:    .        index.html
               dist     mod_perl_traps.html
  Log:
  traps update
  
  Revision  Changes    Path
  1.7       +4 -1      modperl-site/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /export/home/cvs/modperl-site/index.html,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- index.html	1998/05/10 09:58:15	1.6
  +++ index.html	1998/05/14 23:30:05	1.7
  @@ -151,8 +151,11 @@
   
   <a name="more">
   <h3>Additional resources</h3>
  -<a href="src/cgi_to_mod_perl.html">Quick guide</a> for moving from
  +<a href="dist/cgi_to_mod_perl.html">Quick guide</a> for moving from
   CGI to mod_perl.
  +<p>
  +<a href="dist/mod_perl_traps.html">mod_perl_traps</a>, common traps
  +and solutions for mod_perl users.
   <p>
   The mod_perl plugin <a href="src/mod_perl.html">reference guide</a>.
   <p>
  
  
  
  1.2       +210 -5    modperl-site/dist/mod_perl_traps.html
  
  Index: mod_perl_traps.html
  ===================================================================
  RCS file: /export/home/cvs/modperl-site/dist/mod_perl_traps.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- mod_perl_traps.html	1998/03/24 05:11:11	1.1
  +++ mod_perl_traps.html	1998/05/14 23:30:06	1.2
  @@ -22,6 +22,14 @@
   		<LI><A HREF="#Clashes_with_other_Apache_C_modu">Clashes with other Apache C modules</A>
   	</UL>
   
  +	<LI><A HREF="#REGULAR_EXPRESSIONS">REGULAR EXPRESSIONS</A>
  +	<UL>
  +
  +		<LI><A HREF="#COMPILED_REGULAR_EXPRESSIONS">COMPILED REGULAR EXPRESSIONS</A>
  +		<LI><A HREF="#References">References</A>
  +	</UL>
  +
  +	<LI><A HREF="#AUTHORS">AUTHORS</A>
   </UL>
   <!-- INDEX END -->
   
  @@ -64,7 +72,7 @@
   </A></H2>
   <UL>
   <LI><STRONG></STRONG>
  -Be sure to have read <A HREF="././cgi_to_mod_perl.html#">the cgi_to_mod_perl manpage</A>
  +Be sure to have read <EM>cgi_to_mod_perl</EM>
   
   
   
  @@ -212,13 +220,45 @@
   
   <P>
   
  +<DT><STRONG><A NAME="item__Use">"Use of uninitialized value"
  +
  +</A></STRONG><DD>
  +Because of eval context, you may see warnings with useless filename/line,
  +example:
  +
  +
  +<P>
  +
  +<PRE> Use of uninitialized value at (eval 80) line 12.
  + Use of uninitialized value at (eval 80) line 43.
  + Use of uninitialized value at (eval 80) line 44.
  +</PRE>
  +
  +<P>
  +
  +To track down where this eval is really happening, try using a
  +<STRONG>__WARN__</STRONG> handler to give you a stack trace:
  +
  +
  +<P>
  +
  +<PRE> use Carp ();
  + local $SIG{__WARN__} = \&amp;Carp::cluck;
  +</PRE>
  +
  +<P>
  +
  +<DT><STRONG><A NAME="item__Callback">"Callback called exit"
  +
  +</A></STRONG><DD>
   <DT><STRONG><A NAME="item__Out">"Out of memory!"
   
   </A></STRONG><DD>
   If something goes really wrong with your code, Perl may die with an ``Out
  -of memory!'' message. A common cause of this are never-ending loops, deep
  -recursion or calling an undefined subroutine. Here's one way to catch the
  -problem: See Perl's INSTALL document for this item:
  +of memory!'' message and or ``Callback called exit''. A common cause of
  +this are never-ending loops, deep recursion or calling an undefined
  +subroutine. Here's one way to catch the problem: See Perl's INSTALL
  +document for this item:
   
   
   <P>
  @@ -238,11 +278,12 @@
   If you compile with that option and add 'use Apache::Debug level =&gt; 4;'
   to your PerlScript, it will allocate the $^M emergency pool and the
   $SIG{__DIE__} handler will call Carp::confess, giving you a stack trace
  -which should reveal where the problem is. =item *
  +which should reveal where the problem is. See the <STRONG>Apache::Resource</STRONG> module for prevention of spinning httpds.
   
   
   <P>
   
  +<LI><STRONG></STRONG>
   If you wish to use a module that is normally linked static with your Perl,
   it must be listed in static_ext in Perl's Config.pm to be linked with httpd
   during the mod_perl build.
  @@ -343,6 +384,170 @@
   <P>
   
   </DL>
  +<P>
  +<HR>
  +<H1><A NAME="REGULAR_EXPRESSIONS">REGULAR EXPRESSIONS
  +
  +</A></H1>
  +<P>
  +<HR>
  +<H2><A NAME="COMPILED_REGULAR_EXPRESSIONS">COMPILED REGULAR EXPRESSIONS
  +
  +</A></H2>
  +When using a regular expression that contains an interpolated Perl
  +variable, if it is known that the variable (or variables) will not vary
  +during the execution of the program, a standard optimization technique
  +consists of adding the <CODE>o</CODE> modifier to the regexp pattern, to direct the compiler to build the
  +internal table once, for the entire lifetime of the script, rather than
  +every time the pattern is executed. Consider:
  +
  +
  +<P>
  +
  +<PRE>        my $pat = '^foo$'; # likely to be input from an HTML form field
  +        foreach( @list ) {
  +                print if /$pat/o;
  +        }
  +</PRE>
  +
  +<P>
  +
  +This is usually a big win in loops over lists, or when using <CODE>grep</CODE> or
  +<CODE>map</CODE>.
  +
  +
  +<P>
  +
  +In long-lived <CODE>mod_perl</CODE> scripts, however, this can pose a problem if the variable changes according
  +to the invocation. The first invocation of a fresh httpd child will compile
  +the table and perform the search correctly, however, all subsequent uses by
  +the httpd child will continue to match the original pattern, regardless of
  +the current contents of the Perl variables the pattern is dependent on.
  +Your script will appear broken.
  +
  +
  +<P>
  +
  +There are two solutions to this problem.
  +
  +
  +<P>
  +
  +The first is to use <CODE>eval q//</CODE>, to force the code to be evaluated each time. Just make sure that the <CODE>eval</CODE> block covers the entire loop of processing, and not just the pattern match
  +itself.
  +
  +
  +<P>
  +
  +The above code fragment would be rewritten as:
  +
  +
  +<P>
  +
  +<PRE>        my $pat = '^foo$';
  +        eval q{
  +                foreach( @list ) {
  +                        print if /$pat/o;
  +                }
  +        }
  +</PRE>
  +
  +<P>
  +
  +Just saying
  +
  +
  +<P>
  +
  +<PRE>        eval q{ print if /$pat/o; };
  +</PRE>
  +
  +<P>
  +
  +is going to be a horribly expensive proposition.
  +
  +
  +<P>
  +
  +You use this approach if you require more than one pattern match operator
  +in a given section of code. If the section contains only one operator (be
  +it an
  +<CODE>m//</CODE> or <CODE>s///</CODE>), you can rely on the property of the null pattern, that reuses the last
  +pattern seen. This leads to the second solution, which also eliminates the
  +use of <CODE>eval</CODE>.
  +
  +
  +<P>
  +
  +The above code fragment becomes:
  +
  +
  +<P>
  +
  +<PRE>        my $pat = '^foo$';
  +        &quot;something&quot; =~ /$pat/; # dummy match (MUST NOT FAIL!)
  +        foreach( @list ) {
  +                print if //;
  +        }
  +</PRE>
  +
  +<P>
  +
  +The only gotcha is that the dummy match that boots the regular expression
  +engine must absolutely, positively succeed, otherwise the pattern will not
  +be cached, and the // will match everything. If you can't count on fixed
  +text to ensure the match succeeds, you have two possibilities.
  +
  +
  +<P>
  +
  +If you can guaranteee that the pattern variable contains no meta-characters
  +(things like <CODE>*</CODE>, <CODE>+</CODE>, <CODE>^</CODE>, <CODE>$</CODE>...), you can use the dummy match:
  +
  +
  +<P>
  +
  +<PRE>        &quot;$pat&quot; =~ /\Q$pat\E/; # guaranteed if no meta-characters present
  +</PRE>
  +
  +<P>
  +
  +If there is a possibility that the pattern can contain meta-characters, you
  +should search for the pattern or the unsearchable <CODE>\377</CODE> character as follows:
  +
  +
  +<P>
  +
  +<PRE>        &quot;\377&quot; =~ /$pat|^[\377]$/; # guarenteed if meta-characters present
  +</PRE>
  +
  +<P>
  +
  +<P>
  +<HR>
  +<H2><A NAME="References">References
  +
  +</A></H2>
  +<PRE>        The Camel Book, 2nd edition, p. 538 (p. 356 in the 1st edition).
  +</PRE>
  +
  +<P>
  +
  +<P>
  +<HR>
  +<H1><A NAME="AUTHORS">AUTHORS
  +
  +</A></H1>
  +Doug MacEachern, with contributions from Jens Heunemann <A
  +HREF="MAILTO:<he...@janet.de>,</A> David
  +Landgren <A HREF="MAILTO:<da...@landgren.net>,</A>
  +Mark Mills <A HREF="MAILTO:<ma...@ntr.net></A> and Randal
  +Schwartz <A
  +HREF="MAILTO:<me...@stonehenge.com></A>
  +
  +
  +<P>
  +
   </DL>
       </BODY>