in reply to Alternatives to PerlTransHandler?

You don't need mod_perl for that (and if you had it, I wouldn't use a PerlTransHandler for this). Just check out the Apache CGI configuration options. You can make ANYTHING a CGI script, even if it's named foo.html. If you don't like making lots of separate scripts, you could do some magic with mod_rewrite to have them all go tone script.

Replies are listed 'Best First'.
Re: Re: Alternatives to PerlTransHandler?
by BMaximus (Chaplain) on Nov 01, 2001 at 17:43 UTC
    I think that this site (WSMCafe) is a lively example of what SamQi is trying to do. It's all CGI, no mod_perl that I can see.

    perrin, I'm not sure if I agree with you. Could you please elaborate as to why PerlTransHandler isn't good for something like this. Here's a small example of what I'm working on and I'll soon have a working example to show for it. It seems to do its job pretty well, although I'm pretty sure there are some things that need to be improved. I do agree with you on how it really doesn't need mod_perl to be. But I figure if I have it, I use it. It goes on the theory, why keep on querying the database to make the pages when they can be generated as static pages.
    package util::TransHandler; use strict; use Apache::Constants qw(:common); sub handler { my $r = shift; my $uri = $r->uri; my ($host,$port) = split(/:/, $r->headers_in->{'Host'}); lc($host); print STDERR $host,"\n"; # if the hostname has more than one subdomain from the one specifi +ed below, reject it. # bar.slinger.foo.com = OK # bar.baz.slinger.foo.com = NOT OK if ($host =~ m/^([a-z0-9]+\.){2,}\.?slinger\.foo\.com$/) { $r->pnotes('BadHost' => ['1']); return DECLINED; # if its not from the base domain. Process it. Find the files and +return the correct path. } elsif ($host !~ m/^(slinger)?\.?foo.com$/) { $host =~ m/^([a-z0-9]+)\.slinger\.foo.com$/; my $members = MEMBERS->select( { SUBDOMAIN => $1 } ); my $session = SESSIONS->select( { SUBDOMAIN => $1 } ); # if the subdomain exists in the database, process it. # Otherwise let the user know its available to use. if ($members != 0 || $session != 0) { my $thedir = $r->server_root_relative($r->dir_config('User +Dir')); my $result; if (ref($members) eq 'ARRAY') { $result = $members->[0]{DI +RECTORY}; } if (ref($session) eq 'ARRAY') { $result = $session->[0]{DI +RECTORY}; } return DECLINED unless $uri =~ s!^/(.*)$!$thedir/$result/$ +1!; $r->pnotes('DontDo' => ['1']); $r->filename($uri); return OK; } else { # Switch that says the subdomain is available. $r->pnotes('SubDomain' => [$1]); return OK; } } else { return DECLINED; } }

    Any improvements to it would be gladly accepted. This probably looks sloppy to most.

    BMaximus
      If the goal for him was just to have one program handle all of these .html URLs, it's easy to do that with a simple httpd.conf thing like this:
      <Files *.html> # or whatever SetHandler perl-script PerlHandler My::Secret::Handler </Files>
      What you are doing is considerably more complex, and makes sense to do in a TransHandler.