You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jeff <ja...@aquabolt.com> on 2002/03/23 18:30:18 UTC

mod_perl developers cookbook... a kitchen hand asks... doh!

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.

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

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

This is interesting - probably because PerlHandler Apache::Registry so
kitchen whizzes, tell me please, exactly what knead I put in my
httpd.conf instead of Apache::Registry?

Thanks a munch!

Jeff



Re: mod_perl developers cookbook... a kitchen hand asks... doh!

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> 
> "OK" is a constant for the HTTP return code 200.  


close.  OK is 0, which is different from HTTP_OK which is 200.

--Geoff


Re: mod_perl developers cookbook... a kitchen hand asks... doh!

Posted by Ade Olonoh <ol...@yahoo.com>.
 
> 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 a constant for the HTTP return code 200.  Add:

	use Apache::Constants ':common';

to the top of your prog. and it should work.


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

Are you using Apache::StatINC?


--Ade.

Re: mod_perl developers cookbook... a kitchen hand asks... doh!

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

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


Re: mod_perl developers cookbook... a kitchen hand asks... doh!

Posted by Per Einar Ellefsen <pe...@skynet.be>.
At 01:23 25.03.2002, Issac Goldstand wrote:

>>You must have taken this subroutine out of context. There are a certain 
>>number of things which must appear for an Apache handler to work:
>>
>>package Apache::Whatever;
>>
>>You need to have that line to uniquely identify your module. If you use 
>>the name Apache::Whatever, your handler must be named Whatever.pm and be 
>>placed in your @INC search path under Apache/
>>This is probably the reason for your number 2 problem: you must have used 
>>the same package name twice. Or not used a package name at all.
>
>
>Actually, this isn't true.. You don't *have* to use the Apache 
>namespace...  You can just as easily call it Foo::Bar if you'd like... I 
>don't mean to come across as being an extremist on this issue, but we were 
>all newbies once, and I know that as a newbie, *I* would take anything 
>written here as the "authorative" answer, so I didn't want anyone here to 
>be misled...

Yes, sorry, I didn't want to make it appear like you had to use the 
Apache:: namespace. In the Cookbook for example they use the Cookbook:: 
namespace, and you could just as well use Jeff::.


-- 
Per Einar Ellefsen
per.einar@skynet.be


Re: mod_perl developers cookbook... a kitchen hand asks... doh!

Posted by Issac Goldstand <ma...@beamartyr.net>.
>
> You must have taken this subroutine out of context. There are a 
> certain number of things which must appear for an Apache handler to work:
>
> package Apache::Whatever;
>
> You need to have that line to uniquely identify your module. If you 
> use the name Apache::Whatever, your handler must be named Whatever.pm 
> and be placed in your @INC search path under Apache/
> This is probably the reason for your number 2 problem: you must have 
> used the same package name twice. Or not used a package name at all.


Actually, this isn't true.. You don't *have* to use the Apache 
namespace...  You can just as easily call it Foo::Bar if you'd like... 
 I don't mean to come across as being an extremist on this issue, but we 
were all newbies once, and I know that as a newbie, *I* would take 
anything written here as the "authorative" answer, so I didn't want 
anyone here to be misled...

   Issac


Re: mod_perl developers cookbook... a kitchen hand asks... doh!

Posted by Per Einar Ellefsen <pe...@skynet.be>.
At 17:30 23.03.2002 +0000, Jeff wrote:
>Just Curious of Hither Green writes:
>
>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
>
>2) error log: Subroutine handler redefined at xxx line 1
>
>This is interesting - probably because PerlHandler Apache::Registry so
>kitchen whizzes, tell me please, exactly what knead I put in my
>httpd.conf instead of Apache::Registry?

You must have taken this subroutine out of context. There are a certain 
number of things which must appear for an Apache handler to work:

package Apache::Whatever;

You need to have that line to uniquely identify your module. If you use the 
name Apache::Whatever, your handler must be named Whatever.pm and be placed 
in your @INC search path under Apache/
This is probably the reason for your number 2 problem: you must have used 
the same package name twice. Or not used a package name at all.

use Apache::Constants;

This imports the constants like OK, DECLINED, etc... You can also specify 
them explicitly:
use Apache::Constants qw(OK DECLINED);

I hope this helps you out.

-- 

Per Einar Ellefsen
per.einar@skynet.be