dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

I've got a number of reports that are all nearly identical, except for the SQL they run, how they inflate the results, and which template basename they use. Right now, it's running under CGI, but I need to port it to mod_perl handlers.

The question I have is this how do I set up my stuff?

In my httpd.conf, I have the following:

PerlOptions -SetupEnv PerlWarn On PerlTaintCheck On PerlRequire /path/to/startup.pl <Location /reports> SetEnv ORACLE_HOME /where/oracle/lives SetEnv ORA_NLS33 /where/oracle/lives/ocommon/nls/admin/data SetHandler perl-script PerlResponseHandler My::Report::Handler </Location>

Do I have one handler that dispatches the report based on some HTTP param? Or, should I have an entry in httpd.conf for each report, along the lines of:

PerlOptions -SetupEnv PerlWarn On PerlTaintCheck On PerlRequire /path/to/startup.pl <Location /reports/report1> SetEnv ORACLE_HOME /where/oracle/lives SetEnv ORA_NLS33 /where/oracle/lives/ocommon/nls/admin/data SetHandler perl-script PerlResponseHandler My::Report::Handler1 </Location> <Location /reports/report2> SetEnv ORACLE_HOME /where/oracle/lives SetEnv ORA_NLS33 /where/oracle/lives/ocommon/nls/admin/data SetHandler perl-script PerlResponseHandler My::Report::Handler2 </Location>

What are peoples' experiences with this?

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Setting up mod_perl handlers
by jeffa (Bishop) on Nov 21, 2003 at 15:11 UTC
    Just quickly glancing at what you are doing, i say choose the former. You can always determine what URI was passed in:
    sub handler { my $r = shift; my $filename = $r->filename(); my $uri = $r->uri(); .... }
    From there it's just a matter of mapping to the actual page. I would also subclass the individual "handlers" and just call the appriopriate one based on the URI.

    Hope this helps ...

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Setting up mod_perl handlers
by perrin (Chancellor) on Nov 21, 2003 at 17:34 UTC
Re: Setting up mod_perl handlers
by Anonymous Monk on Nov 21, 2003 at 15:12 UTC
    Do I have one handler that dispatches the report based on some HTTP param? Or, should I have an entry in httpd.conf for each report, ...
    Whatever floats your boat. http://server/foo/bar/ maybe easier to remember for users than http://server/foo?bar or http://server/foo?op=bar the same way that http://search.cpan.org/dist/DistName/ is is easier for me to remember than http://search.cpan.org/search?mode=dist&query=DistName
      You can still use the path_info() information and not use the query string at all.

      F.ex. I have an archive for the Sybperl-l mailing list here. The mod_perl handler looks like this:

      <Location /archive> SetHandler perl-script PerlHandler My::Archive </Location>
      However, the "My::Archive" module understands things like: http://www.peppler.org/archive/sybperl-l/2003/11/7567.html by doing the following:
      sub handler { my $r = shift; my $path = $r->path_info(); my $q = Apache::Request->new($r); my $dbh = getDataBaseHandle(); $path =~ s/\.html$//; my ($junk, $list, $year, $mon, $msg) = split(/\//, $path); if(!$year) { displayYears($q, $dbh, $list); } elsif(!$mon) { displayMonths($q, $dbh, $list, $year); } elsif(!$msg) { displayMsgs($q, $dbh, $list, $year, $mon); } else { displayMessage($q, $dbh, $list, $year, $mon, $msg); } }
      ... and yes, the mail archive is stored in a Sybase database.

      Michael

        The programmers POV is unimportant