Jeff wrote:

 > Just Curious of Hither Green writes:
 >
 > I feel like a right tit for asking this...
 >
 > I already have mod_perl et al running, including my persistent DB connections
 >  etc etc, but following gourmet cookery advice on this list induced me to
 > buy a copy of the mod_perl Developers Cookbook... and yes, my nails were
 > rather short after the week it took my Amazon to deliver said arcane tome
 > unto my abode.


I hope you enjoy it and that you didn't bite to the quick...


 >
 > So, I am working my way through, and get to page 83 which has a little spellette:
 >

 >
 > sub handler { my $r = shift; print STDERR $r->as_string(); return OK; }
 >
 > looks easy peasy - but
 >
 > 1) OK ->  Bareword "OK" not allowed while "strict subs" in use well, that's
 > easy to fix - I must be missing a 'use' [which one??] I assume OK is 1 - ie
 >  TRUE


OK is actually 0, but is better used as

use Apache::Constants qw(OK);

as to avoid any real value behind the OK constant.  see recipe 3.12 for more 
details about this notation.


 >
 > 2) error log: Subroutine handler redefined at xxx line 1


well, you have to put handler() in a package first... depending on which package
you put it in, it might redefine something that already exists.


you're coming up against something I struggled with throughout the book.  lots 
of our examples use handler snippets instead of the complete handler.  this is 
because I thought doing this

package Cookbook::Foo;

use Apache::Constants qw(:common);
use strict;

sub handler {
  ...
}

1;

wasted lots of space - in this particular instance the other cruft is longer 
than the code we were illustrating :)

so I basically took the point of view that for shortish stuff enforcing the 
handler() meme was good enough, and the package stuff could be reinforced 
elsewhere.  and there's always the eagle book in addition to our stuff.

I hope that as you read through the rest of the book things start solidifying...

HTH

--Geoff

Reply via email to