On Mon, 17 Apr 2000, Vivek Khera wrote:

> >>>>> "MS" == Matt Sergeant <[EMAIL PROTECTED]> writes:
> 
> >> adding handlers as easy as adding Registry scripts.  I guess it is
> >> sort of an ultra-light-weight Registry, in some sense.
> 
> MS> I've got something pretty similar. Let me know if you want some code.
> 
> Sure; it is always good to see other ideas...
> 
> Which handler phase did you tie into?  I'm thinking just to go along
> the lines of Apache::Registry and use the content phase.

PerlFixupHandler. That way I eliminate stat() calls. At the end of the
fixup handler I push an ordinary PerlHandler onto the stack, which deals
with the main content delivery. But I suppose you could have the Fixup
handler determine what phase to use, via a call to a method in the module
you've used.

Anyway, here's the relevant bit of code, typed in and untested because
it's part of something much larger, so it might not quite work, but
hopefully you'll get the idea:

package Whatever;

sub fixup {
my $r = shift;

my $loc = $r->location;
my $handler = $r->uri;
if ($loc) {
        $loc =~ s/\.\*$//; # remove wildcards
        $loc =~ s/^\^//; # remove anchor at start

        $prefix = $loc;

        $handler =~ s/^\Q$loc\E//; # strip location from uri
}
else {
        # handler starts from / (sensible?)
        $handler =~ s/^\///;
}

$handler =~ s/\//::/g; # change / to ::
$handler =~ s/(.*)::/$1\->/; # change last :: to ->

my $module = $handler;
$module =~ s/\->.*$//;

eval {
        require $module;
        import $module;
}
if ($@) {
        return 404;
}

no strict 'refs';

my $handler = $module->which_handler || 'PerlHandler';

$r->push_handlers( $handler, \&{$handler} );#
return OK;
}

Stick it as a PerlFixupHandler in a <Location> or <LocationMatch>
directive.

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org

Reply via email to