[RFC] Apache2::DirBasedHandler

2008-01-19 Thread adam . prime


I've found myself writing similar bits of code repeatedly, and figure  
what i'm doing is probably common enough that something like this  
could have a place on CPAN.  I'm mostly curious about if the name is  
appropriate.


This is just a base class designed to speed the implementation of  
handlers that happen to work in this way.  I plan to do a subclass of  
this that'll have the generic TT generation stuff i'm always using  
stuck into it as well.  I could also see other generic base classes  
like this that might want to make uri's differently.


The idea of this handler is basically to take $r->uri, and map that to  
a function.  Similar to Apache::Dispatch, similar to what Catalyst  
does and similar to about a lot of other code i'm sure.  This thing  
does work slightly differently though, because i often need it to.


Here's a quick outline of what it does.

Given a request for /foo/bar/haha/hoho

It will loop through the split uri checking for the existance of  
subroutines like this:


foo_bar_haha_hoho_page
foo_bar_haha_page
foo_bar_page
foo_page
index

As soon as it finds one, it uses that function to generate the page.   
The part of the URI that isn't in the function name gets stuck into an  
array reference and passed into the actual page generation function  
function like this


$self->function($r,$uri_leftovers,$args)

$args is whatever you want it to be, and is generated by a call to  
$self->init($r).


here's some code to look at:

http://kabob.ca/perl/DirBasedHandler.pm

Any input would be appreciated.  I don't really even know if anyone  
other than me is writing ResponseHandlers in this fashion, or if  
everyone is just using Registry, or one of the various frameworks.


Adam



Re: question on startup.pl overriding perl search path

2008-01-19 Thread c chan


-Original Message-
>From: Adam Prime <[EMAIL PROTECTED]>
>Sent: Jan 18, 2008 6:22 AM
>To: c chan <[EMAIL PROTECTED]>
>Cc: modperl@perl.apache.org
>Subject: Re: question on startup.pl overriding perl search path
>
>c chan wrote:
>> I use "PerlConfigRequire /var/www/html/mypath/startup.pl" in httpd.conf to 
>> recompile all the CGIs. Inside startup.pl, I added the line:
>> 
>>   use lib qw(. mylib);
>> 
>> To me amazement, after all the CGI is precompiled, they start to look into 
>> the "." and "mylib" path for loading Perl Modules without even having the 
>> line [use lib qw(. mylib);] incorporated in each individual cgi script. 
>> 
>> Can someone explain to me why this is the case? Is the mod_perl startup.pl 
>> script simply becomes the parent apache process for all the preloaded CGIs?
>
>This is normal.  Under mod_perl the perl interpreter just keeps running 
>until the apache child dies your modified @INC stays modified.  I'm sure 
>someone with a better understanding of the internals can give a more 
>detailed 'why'.  FYI though, you should probably use PerlPostConfigRequire
>
>http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPostConfigRequire_
>
>> If I remove mod_perl, can I use the 
>> 
>>   PerlSetEnv -I/var/www/html/mypath -I/var/www/html/mypath/lib 
>> 
>> to achieve the same result.
>
>Isn't PerlSetEnv part of mod_perl?  In which case, no that wouldn't work 
>if you'd removed mod_perl
Thank you for your clarification. To make the CGI scripts both work under 
Apache and mod_perl, I put the "use lib qw(...);" in everyone of them.

- Clement 
>
>> This will make a profound effect on my CGI directory because whatever I 
>> installed will no longer affect the system perl module search path. In 
>> effect, this will make my application self contained and making trouble 
>> shooting make easier.
>> 
>> - C Chan
>
>Adam