git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH/RFC 4/6] gitweb: Prepare for mod_perl specific support
Date: Thu, 28 Dec 2006 00:04:32 +0100	[thread overview]
Message-ID: <200612280004.32728.jnareb@gmail.com> (raw)
In-Reply-To: <200612272355.31923.jnareb@gmail.com>

Prepare gitweb for mod_perl specific support in CGI compatibility mode
(Apache::Registry/ModPerl::Registry or Apache::PerlRun/ModPerl::PerlRun)
by storing request (an argument to a handler) in $r variable, for later
use.

The idea is to have gitweb run as CGI script, under mod_perl 1.0 and under
mod_perl 2.0 without modifications, while being able to make use of mod_perl
capabilities.

Define MP_GEN constant and set it to 0 if mod_perl is not available,
to 1 if running under mod_perl 1.0, and 2 for mod_perl 2.0. It is later used
in BEGIN block to load appropriate mod_perl modules; for now the one
in which request is defined, and the one with status and HTTP constants.
Based on "Porting Apache:: Perl Modules from mod_perl 1.0 to 2.0" document
  http://perl.apache.org/docs/2.0/user/porting/porting.html
chapter "Making Code Conditional on Running mod_perl Version".

Use "if (MP_GEN)" for checking if gitweb is run under mod_perl; later
on we will use "if ($r)" for that.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
A bit of RFC, because I'm not sure if "my $r" or "our $r" should be
used (in script which makes use of subroutines; under Registry those
would end as nested subroutines).

Perhaps we should import everything?

 gitweb/gitweb.perl |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 3888563..9983e9e 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -18,10 +18,36 @@ use File::Find qw();
 use File::Basename qw(basename);
 binmode STDOUT, ':utf8';
 
+# Set the constant MP_GEN to 0 if mod_perl is not available,
+# to 1 if running under mod_perl 1.0
+# and 2 for mod_perl 2.0
+use constant {
+	MP_GEN => ($ENV{'MOD_PERL'}
+	           ? ( exists $ENV{'MOD_PERL_API_VERSION'} and 
+	                      $ENV{'MOD_PERL_API_VERSION'} >= 2 ) ? 2 : 1
+	           : 0),
+};
+
 BEGIN {
-	CGI->compile() if $ENV{MOD_PERL};
+	# use appropriate mod_perl modules (conditional use)
+	if (MP_GEN == 2) {
+		require Apache2::RequestRec;
+		require Apache2::Const;
+		Apache2::Const->import(-compile => qw(:common :http));
+	} elsif (MP_GEN == 1) {
+		require Apache;
+		require Apache::Constants;
+		Apache::Constants->import(qw(:common :http));
+	}
+
+	# precompile CGI for mod_perl
+	CGI->compile() if MP_GEN;
 }
 
+# mod_perl request
+my $r;
+$r = shift @_ if MP_GEN;
+
 our $cgi = new CGI;
 our $version = "++GIT_VERSION++";
 our $my_url = $cgi->url();
-- 
1.4.4.3

  parent reply	other threads:[~2006-12-28  0:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-27 22:55 [PATCH 0/6] gitweb: Some mod_perl specific support (but not only) Jakub Narebski
2006-12-27 22:57 ` [PATCH 1/6] gitweb: Separate HTTP header output Jakub Narebski
2006-12-28  1:23   ` Junio C Hamano
2006-12-28  1:28     ` Shawn Pearce
2006-12-27 22:59 ` [PATCH 2/6] gitweb: Add mod_perl version string to "generator" meta header Jakub Narebski
2006-12-27 23:00 ` [PATCH 3/6] gitweb: Precompile CGI routines for mod_perl Jakub Narebski
2006-12-27 23:04 ` Jakub Narebski [this message]
2006-12-27 23:49 ` [PATCH/RFC 5/6] gitweb: Make possible to run under mod_perl without SetupEnv Jakub Narebski
2006-12-28  0:06 ` [RFC/PATCH 6/6] gitweb: Make possible to run under mod_perl without ParseHeaders Jakub Narebski
2006-12-28  1:03   ` Robert Fitzsimons
2006-12-28  1:12     ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200612280004.32728.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).