This is just a little something I wrote up in about 20 minutes. The place where I work at has a few virtual servers, and most users have CGI scripts on them. Problem is, they have the .cgi extension on them and I couldn't take advantage of the speed of mod_perl, so I wrote a PerlHandler to automatically determine if a CGI script was written in Perl or some other language and point it to the correct handler.
CGIAutoDetect.pm (this should go in /usr/local/apache or wherever you install your PerlHandlers):
#!/usr/bin/perl # CGIAutoDetect: take full advantage of mod_perl without renaming scri +pts # Mooneer Salem <mooneer@translator.cx> package CGIAutoDetect; use Apache::Constants qw(:common); use Apache::PerlRun; use CGI::Carp qw(fatalsToBrowser); sub handler { my $r = shift; my $filename = $r->filename; my $line; open(FP, $filename) or sub { $r->content_type("text/html"); $r->print("$filename: not found"); return OK; }; $line = <FP>; close(FP); if ($line =~ /perl/o) { $r->push_handlers("PerlHandler", \&Apache::PerlRun::ha +ndler); $r->handler('perl-script'); } else { $r->handler('cgi-script'); } return DECLINED; }
You also need something like this in your httpd.conf file (make sure you comment out the AddHandler cgi-script line before you add it though):
PerlModule CGIAutoDetect <Files *.cgi> SetHandler perl-script PerlHandler CGIAutoDetect PerlSendHeader On Options ExecCGI </Files>

In reply to Automatically using mod_perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.