git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* gitweb: Version independent mod_perl woes
@ 2006-12-21 17:07 Jakub Narebski
  2006-12-21 17:51 ` Jakub Narebski
  2006-12-21 18:09 ` Jakub Narebski
  0 siblings, 2 replies; 3+ messages in thread
From: Jakub Narebski @ 2006-12-21 17:07 UTC (permalink / raw)
  To: git

I try to make gitweb run under mod_perl without need to set up CGI
environmental variables, and without need to parse headers. I try to do
this in such a way that one will be able to run gitweb under mod_cgi
(as an ordinary CGI script), under mod_perl 1.0 Apache::registry and
under mod_perl 2.0 ModPerl::Registry without changes.

I'm trying to do the first part (running without need for SetupEnv),
but I'm encountering some strange errors and I'm stumped.

I have taken the version independent initialization from
  http://perl.apache.org/docs/2.0/user/porting/porting.html#Making_Code_Conditional_on_Running_mod_perl_Version

-- >8 --
# 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;

# use appropriate mod_perl modules (conditional use)
BEGIN {
	if (MP_GEN == 2) {
		require Apache2::RequestRec;
		require Apache2::ServerRec;
		require Apache2::Response;
		require Apache2::Const;
		import Apache2::RequestRec;
		import Apache2::ServerRec;
		Apache2::Const->import(-compile => qw(:common :http));
	} elsif (MP_GEN == 1) {
		require Apache;
		require Apache::Constants;
		import Apache;
		Apache::Constants->import(qw(:common :http));
	}
}

# mod_perl request
my $r;
$r = shift @_ if MP_GEN;
-- >8 --

Then later I try to use mod_perl rather than $ENV{'SERVER_NAME'}

-- >8 --
# name of your site or organization to appear in page titles
# replace this with something more descriptive for clearer bookmarks
our $site_name = "++GITWEB_SITENAME++"
                 || (($r ? $r->server()->server_hostname() : $ENV{'SERVER_NAME'})
                     || "Untitled") . " Git";
-- >8 --

but I'm encountering the following error:

  Can't locate object method "server_hostname" via package "Apache2::ServerRec"
  at /var/www/perl/gitweb/gitweb.cgi line 83.

What is strange from time to time it _works_.


Can anyone tell me what I'm doing wrong?
-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gitweb: Version independent mod_perl woes
  2006-12-21 17:07 gitweb: Version independent mod_perl woes Jakub Narebski
@ 2006-12-21 17:51 ` Jakub Narebski
  2006-12-21 18:09 ` Jakub Narebski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Narebski @ 2006-12-21 17:51 UTC (permalink / raw)
  To: git

> Can anyone tell me what I'm doing wrong?

Ah, I forgot to add:

Apache 2.0.54 (httpd-2.0.54-10.3)
mod_perl 2.0.1 (mod_perl-2.0.1-1.fc4)
Perl 5.8.6 (perl-5.8.6-24)

$Apache2::RequestRec::VERSION = 2.000001
$Apache2::ServerRec::VERSION  = 2.000001

-- >8 -- [fragment of httpd.conf] ---
Alias /perl "/var/www/perl"
<Directory "/var/www/perl">
    SetHandler perl-script
    PerlResponseHandler ModPerl::Registry
    PerlOptions +ParseHeaders
    Options Indexes FollowSymlinks +ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
-- >8 --

P.S. The goal is for gitweb to work with
    PerlOptions -SetupEnv -ParseHeaders
-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gitweb: Version independent mod_perl woes
  2006-12-21 17:07 gitweb: Version independent mod_perl woes Jakub Narebski
  2006-12-21 17:51 ` Jakub Narebski
@ 2006-12-21 18:09 ` Jakub Narebski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Narebski @ 2006-12-21 18:09 UTC (permalink / raw)
  To: git

Jakub Narebski wrote:
> -- >8 --
> # 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;

Actually, the error was here. It works like expected for

 use constant {
 	MP_GEN => ($ENV{'MOD_PERL'}
 	           ? ( exists $ENV{'MOD_PERL_API_VERSION'} and 
 	               $ENV{'MOD_PERL_API_VERSION'} >= 2 ) ? 2 : 1
 	           : 0),
 };

> # use appropriate mod_perl modules (conditional use)
> BEGIN {
>         if (MP_GEN == 2) {
>                 require Apache2::RequestRec;
>                 require Apache2::ServerRec;
>                 require Apache2::Response;
>                 require Apache2::Const;
>                 import Apache2::RequestRec;
>                 import Apache2::ServerRec;
>                 Apache2::Const->import(-compile => qw(:common :http));
>         } elsif (MP_GEN == 1) {
>                 require Apache;
>                 require Apache::Constants;
>                 import Apache;
>                 Apache::Constants->import(qw(:common :http));
>         }
> }
> 
> # mod_perl request
> my $r;
> $r = shift @_ if MP_GEN;
> -- >8 --

Sorry for the noise.
-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-12-21 18:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-21 17:07 gitweb: Version independent mod_perl woes Jakub Narebski
2006-12-21 17:51 ` Jakub Narebski
2006-12-21 18:09 ` Jakub Narebski

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).