git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 4/6] gitweb: Prepare for mod_perl specific support

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 27, 2006, 23:04 UTC
Message-ID
<200612280004.32728.jnareb@gmail.com>
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
Previous: Jakub NarebskiNext: Jakub Narebski
Message 7 of 11 in “gitweb: Some mod_perl specific support (but not only)”
  1. 0/6 gitweb: Some mod_perl specific support (but not only)Jakub Narebski, Dec 27, 2006
  2. 1/6 gitweb: Separate HTTP header outputJakub Narebski, Dec 27, 2006
  3. Junio C HamanoDec 28, 2006
  4. Shawn PearceDec 28, 2006
  5. 2/6 gitweb: Add mod_perl version string to "generator" meta headerJakub Narebski, Dec 27, 2006
  6. 3/6 gitweb: Precompile CGI routines for mod_perlJakub Narebski, Dec 27, 2006
  7. 4/6 gitweb: Prepare for mod_perl specific supportJakub Narebski, Dec 27, 2006
  8. 5/6 gitweb: Make possible to run under mod_perl without SetupEnvJakub Narebski, Dec 27, 2006
  9. 6/6 gitweb: Make possible to run under mod_perl without ParseHeadersJakub Narebski, Dec 28, 2006
  10. Robert FitzsimonsDec 28, 2006
  11. Jakub NarebskiDec 28, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.