You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tim Esselens <ti...@gmail.com> on 2005/07/22 22:39:00 UTC

[mp2] Runtime PerlResponseHandler

Hi,

I'm having problems with the following construct:

-[httpd.conf]------------------------------------
<FilesMatch \.phtml$>
        PerlInitHandler Dispatcher
</FilesMatch>

-[Dispatcher.pm]---------------------------------
sub handler() {
        # do some stuff to get $module
        $r->push_handlers(PerlResponseHandler => $module);
        return Apache2::Const::OK;
}

If I request http://localhost/index.phtml everything works perfectly
If I request http://localhost/ which in turn uses the DirectoryIndex
directive to get to index.phtml, the file is served from disk w/o using the
handler (as if it were a normal html file).

Thing is, If I add the following to my httpd.conf (say $module was Test::X)
everything works out fine (both URIs are processed by Test::X->handler())

<FilesMatch \.phtml$>
        PerlResponseHandler Test::X
</FilesMatch>

Is PerlInitHandler a hook too early for adding PerlResponseHandlers?
Is there something special I need to do when I'm in my Dispatcher's handler?
(ie: return DECLINED or something similar to force processing of other
handlers maybe? I'm clueless)

--
kind regards,
Tim Esselens


Re: [mp2] Runtime PerlResponseHandler

Posted by Tim Esselens <ti...@gmail.com>.
Geoffrey Young wrote:
 
>>         $r->push_handlers(PerlResponseHandler => $module); 
> you also need $r->handler('modperl') here, as apache needs to know which
> content handler to dispatch to.

I've added this before and after push_handlers, also tried
$r->handler('perl-script') but none of them had any visible effect.

I'm still investigating why my problem occurs but I'm guessing it's an
Apache issue, I was able to call my handler for directories using this:

<LocationMatch "/$">
        PerlInitHandler Dispatcher
</LocationMatch>

But this doesn't really solve my problem since my Dispatcher gets hit too
early in the chain, the code behind it (CGI::Builder::Magic) doesn't get
the template name (index.phtml). I'm presuming this is because the uri (/)
isn't translated to the directoryindex (/index.phtml) yet.

I'll report back If I have any more clues.

> --Geoff
--
kind regards.
Tim Esselens



Re: [mp2] Runtime PerlResponseHandler

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>         $r->push_handlers(PerlResponseHandler => $module);

you also need $r->handler('modperl') here, as apache needs to know which
content handler to dispatch to.

HTH

--Geoff

Re: [mp2] Runtime PerlResponseHandler

Posted by Tim Esselens <ti...@gmail.com>.
Philippe M. Chiasson wrote:

>> Is PerlInitHandler a hook too early for adding PerlResponseHandlers?
 
> Not too early, but the mapping / => index.phtml is done by mod_autoindex
> at a later phase, so when your InitHandler _could_ kick in, the request
> still has $r->filename point to the directory, FIlesMatch \.phtml$ _not_
> matching.
 
> You should try something like:
 
> <Directory /top/level/path/where/your/files/are>
>   PerlInitHandler Dispatcher
> </Directory>
 
> sub handler() {
> my $r = shift;
> return DECLINED unless $r->filename =~ /\.phtml$/;
> [...]
> }

That didn't work either, since it blocked mod_dir, but I've found a FixUp
handler suggestion from Geoff (I hope he doesn't mind I'm referring with
his signing name :))
http://www.issociate.de/board/post/199936/DirectoryIndex_ignored_when_using_perl-handler.html

combining your handler (with regex /(?:\.phtml|\/)$/ together with the FixUp
handler and
<Location /> #I want this for all my virtualhost's docroots
        PerlInitHandler Dispatcher
        PerlFixUpHandler FixUp 
</Location>

made things work exactly as I want. Only downside is that now, all my
DirectoryIndex'ed files go through my dispatcher, I presume that since the
Dispatcher is called from PerlInitHandler, $r->filename is still pointing
to / ?
--
kind regards,
Tim Esselens




Re: [mp2] Runtime PerlResponseHandler

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Tim Esselens wrote:
> Hi,
> 
> I'm having problems with the following construct:
> 
> -[httpd.conf]------------------------------------
> <FilesMatch \.phtml$>
>         PerlInitHandler Dispatcher
> </FilesMatch>
> 
> -[Dispatcher.pm]---------------------------------
> sub handler() {
>         # do some stuff to get $module
>         $r->push_handlers(PerlResponseHandler => $module);
>         return Apache2::Const::OK;
> }
> 
> If I request http://localhost/index.phtml everything works perfectly
> If I request http://localhost/ which in turn uses the DirectoryIndex
> directive to get to index.phtml, the file is served from disk w/o using the
> handler (as if it were a normal html file).
> 
> Thing is, If I add the following to my httpd.conf (say $module was Test::X)
> everything works out fine (both URIs are processed by Test::X->handler())
> 
> <FilesMatch \.phtml$>
>         PerlResponseHandler Test::X
> </FilesMatch>
> 
> Is PerlInitHandler a hook too early for adding PerlResponseHandlers?

Not too early, but the mapping / => index.phtml is done by mod_autoindex at
a later phase, so when your InitHandler _could_ kick in, the request still
has $r->filename point to the directory, FIlesMatch \.phtml$ _not_ matching.

You should try something like:

<Directory /top/level/path/where/your/files/are>
  PerlInitHandler Dispatcher
</Directory>

sub handler() {
	my $r = shift;
	return DECLINED unless $r->filename =~ /\.phtml$/;
	[...]
}

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5