stas        02/04/27 11:32:39

  Modified:    src/docs/1.0/guide Changes.pod porting.pod
  Log:
  new section "Preventing Apache::Constants Stringification"
  Submitted by: Per Einar Ellefsen <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.15      +3 -0      modperl-docs/src/docs/1.0/guide/Changes.pod
  
  Index: Changes.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/docs/1.0/guide/Changes.pod,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Changes.pod       21 Apr 2002 05:00:09 -0000      1.14
  +++ Changes.pod       27 Apr 2002 18:32:39 -0000      1.15
  @@ -17,6 +17,9 @@
   
   * guide::porting
   
  +  o add a new section "Preventing Apache::Constants Stringification"
  +    [Per Einar]
  +
     o add a new section presenting a hackish solution for libraries
       collision, via do() or %INC mangling.
   
  
  
  
  1.9       +51 -0     modperl-docs/src/docs/1.0/guide/porting.pod
  
  Index: porting.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/docs/1.0/guide/porting.pod,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- porting.pod       17 Apr 2002 04:38:52 -0000      1.8
  +++ porting.pod       27 Apr 2002 18:32:39 -0000      1.9
  @@ -3157,6 +3157,57 @@
   
   =back
   
  +=head1 Preventing Apache::Constants Stringification
  +
  +In mod_perl, you are going to use a certain number of constants in
  +your code, mainly exported from C<Apache::Constants>. However, in some
  +cases, Perl will not understand that the constant you're trying to
  +call is really a constant, but interprets it as a string. This is the
  +case with the hash notation C<=E<gt>>, which automatically stringifies
  +the key.
  +
  +For example:
  +
  +  $r->custom_response(FORBIDDEN => "File size exceeds quota.");
  +
  +This will not set a custom response for C<FORBIDDEN>, but for the
  +string C<"FORBIDDEN">, which clearly isn't what is expected. You'll
  +get an error like this:
  +
  +  [Tue Apr 23 19:46:14 2002] null: Argument "FORBIDDEN" isn't numeric
  +                             in subroutine entry at ...
  +
  +Therefore, you can avoid this by not using the hash notation for
  +things that don't require it.
  +
  +  $r->custom_response(FORBIDDEN,  "File size exceeds quota.");
  +
  +There are other workarounds, which you should avoid using unless you
  +really have to use hash notation:
  +
  +  my %hash = (
  +      FORBIDDEN()    => 'this is forbidden',
  +      +AUTH_REQUIRED => "You aren't authorized to enter!",
  +  );
  +
  +Another important note is that you should be using the correct
  +constants defined here, and not direct HTTP codes. For example:
  +
  +  sub handler {
  +      return 200;
  +  }
  +
  +Is not correct. The correct use is:
  +
  +  use Apache::Constants qw(OK);
  +  
  +  sub handler {
  +      return OK;
  +  }
  +
  +Also remember that C<OK != HTTP_OK>.
  +
  +
   =head1 Transitioning from Apache::Registry to Apache handlers
   
   Even if you are a CGI script die-hard at some point you might want to
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to