You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by angie ahl <an...@gmail.com> on 2005/09/28 15:45:59 UTC

[MP2] Using PerlAccessHandler to set PerlResponsehandler

Hi List

I'm trying to work out how to set a PerlResponseHandler within a
PerlAccessHandler

Notes:
	There's only 1 PerlResponsehandler and PerlAccessHandler per request.
	

I was setting the PerlResponsehandler for a vhost in httpd.conf like this:

	<FilesMatch "\.html$">
		SetHandler perl-script
		PerlResponsehandler weblobe2::mainhook
	</FilesMatch>
	
I've commented out these lines and moved the setting of the
PerlResponsehandler over to the accesshandler

I thought I could set the PerlResponsehandler like this:

#!/usr/bin/perl
package weblobe2::mainaccess;
# Check for undeclared variables.
use Apache2::Const qw(OK);
use strict;
use warnings;
use DBI;

sub handler {
	my $r = shift;
	my $ok = $r->set_handlers(PerlResponseHandler => ['weblobe2::mainhook']);
	
	return Apache2::Const::OK;
}
1;

But it's not setting the PerlResponseHandler it's just calling the
file from the file system.
$ok does have a value of 1.

Do I need to set the SetHandler to perl-script in the AccessHandler?

End goal is I want to check to see if theres already a physical file
on the system and return that if there is.
The next stage is to see if there is content stored in a DB and if
it's newer than the file on the system use that.
ie call weblobe2::mainhook

Cna anyone see what I'm missing? Should I be calling 
Apache2::RequestRec or something like that.
The Docs are just confusing me today.

MP2, Apache2 on OS X 10.3

Any of you gurus got a minute to help me.

TIA

Angie

Re: [MP2] Using PerlAccessHandler to set PerlResponsehandler

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> Do I need to set the SetHandler to perl-script in the AccessHandler?

yes.

  $r->handler('perl-script');

> 
> End goal is I want to check to see if theres already a physical file
> on the system and return that if there is.
> The next stage is to see if there is content stored in a DB and if
> it's newer than the file on the system use that.
> ie call weblobe2::mainhook

I don't know why you would be using a PerlAccessHandler for this.

the request cycle gives you the opportunity to decided the request's fate at
different logical points.  the PerlAccessHandler is for denying access to
content based on certain criteria, such as IP for example, so it's not
necessarily idiomatic to be doing this kind of thing there.  if you want to
dynamically serve content conditionally based on various criteria you might
want to try a PerlFixupHandler with something like the following

  if (-e $r->filename) {
    $r->handler('default-handler');
  }
  else {
    # use the configured perl-script to serve a file from a database
  }

apache's default-handler is very efficient at sending flat files, so you
probably should use it whenever possible.  placing that logic in a fixup
handler gives apache every chance to process the file "normally" with
mod_perl stepping in only at the last minute to serve the content from a
dynamic source.

HTH

--Geoff

Re: [MP2] Using PerlAccessHandler to set PerlResponsehandler

Posted by angie ahl <an...@gmail.com>.
Solved it:

needed to set handler to perl-script

sub handler {
	my $r = shift;
	if ($r->uri =~ m#(\.html|/)$#) {
		my $prev_handler = $r->handler('perl-script');
		my $ok = $r->set_handlers(PerlResponseHandler => 'weblobe2::mainhook');
	}
	
	return Apache2::Const::OK;
}
1;

On 9/28/05, angie ahl <an...@gmail.com> wrote:
> Hi List
>
> I'm trying to work out how to set a PerlResponseHandler within a
> PerlAccessHandler
>
> Notes:
>         There's only 1 PerlResponsehandler and PerlAccessHandler per request.
>
>
> I was setting the PerlResponsehandler for a vhost in httpd.conf like this:
>
>         <FilesMatch "\.html$">
>                 SetHandler perl-script
>                 PerlResponsehandler weblobe2::mainhook
>         </FilesMatch>
>
> I've commented out these lines and moved the setting of the
> PerlResponsehandler over to the accesshandler
>
> I thought I could set the PerlResponsehandler like this:
>
> #!/usr/bin/perl
> package weblobe2::mainaccess;
> # Check for undeclared variables.
> use Apache2::Const qw(OK);
> use strict;
> use warnings;
> use DBI;
>
> sub handler {
>         my $r = shift;
>         my $ok = $r->set_handlers(PerlResponseHandler => ['weblobe2::mainhook']);
>
>         return Apache2::Const::OK;
> }
> 1;
>
> But it's not setting the PerlResponseHandler it's just calling the
> file from the file system.
> $ok does have a value of 1.
>
> Do I need to set the SetHandler to perl-script in the AccessHandler?
>
> End goal is I want to check to see if theres already a physical file
> on the system and return that if there is.
> The next stage is to see if there is content stored in a DB and if
> it's newer than the file on the system use that.
> ie call weblobe2::mainhook
>
> Cna anyone see what I'm missing? Should I be calling
> Apache2::RequestRec or something like that.
> The Docs are just confusing me today.
>
> MP2, Apache2 on OS X 10.3
>
> Any of you gurus got a minute to help me.
>
> TIA
>
> Angie
>