modperl-methods_of_dynamic_URL_aliasing

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



To: modperl@apache.org
From: Alastair Stuart <al@quirk.co.za>
Subject: modperl questions
Date: Tue, 18 Dec 2001 16:38:53 +0200

[...]

question one

There is a need to add new client profiles to the centralised
database, which create new application filesystems, new database
structures and CGI trees.  Thus a new profile can be created
and activated with the push of a few buttons, but, as it stands,
the cgi structure looks like this

https://www.foo.co.za/cgi-bin/client1/index.pl
https://www.foo.co.za/cgi-bin/client2/index.pl

it would be better if it was

https://www.foo.co.za/client1
https://www.foo.co.za/client2

just using normal aliasing,

but now the problem,

  -- how to add new aliases to httpd.conf or ./conf/clients.pl
without having to restart apache ??



second question:

Now that we have multiple application and databse instances
running concurrently, how do we ensure that filehandle and
Apache::DBI symbols are reliably encapsulated in their
own namespsaces, all running off the same codebase ?

===

To: "Alastair Stuart" <al@quirk.co.za>, <modperl@apache.org>
From: "Maarten Koskamp" <mkoskamp@kluwer.nl>
Subject: Re: modperl questions
Date: Tue, 18 Dec 2001 15:56:43 +0100


"Alastair Stuart" <al@quirk.co.za> wrote: 

[snip]

> -- how to add new aliases to httpd.conf or ./conf/clients.pl
> without having to restart apache ??

Why not use a perl handler?
Put all the logic in perl libraries and not perl scripts.
Make 1 perl package for communicatio between apache and the perl library.
Then define a location in the apache handler once:

<Location /Client>
SetHandler perl-script
PerlHandler FOO::Client
</Location>

In the package FOO::Client make a subroutine named "handler".

use FOO::SomeApplication;

sub handler {
 my $r = shift;
 my ($command, $params) = split ("&", $r->args, 2);
 my %params = map {s/\+/ /g; s/%([0-9a-zA-Z]{2})/chr(hex($1))/eg; $_} map
{split /=|$/, $_, 2} split /&/, $r->args();
    $params = "&$params" if $params;
    my $client = substr ($r->path_info(),1);
  # do your stuff here
}

Then you can use UR's like:

https://www.foo.co.za/Client/johnson
https://www.foo.co.za/Client/Pete

The URL will not point to a file, but to a resource.
Th eclient name will be in $client in the handler shown above.

Hope this puts you in the right direction.


> second question:
>
> Now that we have multiple application and database instances
> running concurrently, how do we ensure that filehandle and
> Apache::DBI symbols are reliably encapsulated in their
> own namespsaces, all running off the same codebase ?
>

See above

You can use different perl packages for each <Location ....>
So you can use multiple applications.
You can even set HTTP authentication for each <Location...>

This way you might be able to use you existing perl packages without
migrating them.

Hope this puts you in the right direction.

===

To: "Alastair Stuart" <al@quirk.co.za>, <modperl@apache.org>
From: "Perrin Harkins" <perrin@elem.com>
Subject: Re: modperl questions
Date: Tue, 18 Dec 2001 10:17:25 -0500

> as it stands,
> the cgi structure looks like this
>
> https://www.foo.co.za/cgi-bin/client1/index.pl
> https://www.foo.co.za/cgi-bin/client2/index.pl
>
> it would be better if it was
>
> https://www.foo.co.za/client1
> https://www.foo.co.za/client2

You can just use this in your httpd.conf:

DirectoryIndex index.pl

> Now that we have multiple application and databse instances
> running concurrently, how do we ensure that filehandle and
> Apache::DBI symbols are reliably encapsulated in their
> own namespsaces, all running off the same codebase ?

Apache::DBI will only give you back a cached connection if your connecion
parameters (user, login, etc.) are exactly the same.  If different clients
connect to different databases, this should be fine.  You won't accidentally
get the wrong one.

As for filehandles, I suggest you use lexically scoped ones if possible.

===

To: Alastair Stuart <al@quirk.co.za>
From: Scott Alexander <mod_perl@humak.edu>
Subject: Re: modperl questions
Date: Tue, 18 Dec 2001 19:47:55 +0200 (EET)

On Tue, 18 Dec 2001, Alastair Stuart wrote:

> question one
>
> There is a need to add new client profiles to the centralised
> database, which create new application filesystems, new database
> structures and CGI trees.  Thus a new profile can be created
> and activated with the push of a few buttons, but, as it stands,
> the cgi structure looks like this
>
> https://www.foo.co.za/cgi-bin/client1/index.pl
> https://www.foo.co.za/cgi-bin/client2/index.pl
>
> it would be better if it was
>
> https://www.foo.co.za/client1
> https://www.foo.co.za/client2
>
> just using normal aliasing,
>
> but now the problem,
>
>
> -- how to add new aliases to httpd.conf or ./conf/clients.pl
> without having to restart apache ??

I've used

RewriteEngine on
RewriteRule ^/bin/([^/]+)/(.*) /usr/local/systems/work/$2


and then

sub db {
        # get the $db from the url
        my @split_line = split /\//, $ENV{"REQUEST_URI"} ;
        my $db = $split_line[2] ;
        return $db ;
}

and the $db I use to get a db handle

That's how I do it but my application leans towards cgi than mod_perl.

I have 4 different types of systems using the same codebase. Alltogether
13 systems. Works well.

===


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu