{"thread":{"id":"6063","subject":"gitweb: Version independent mod_perl woes","startedAt":"2006-12-21T17:07:53Z","lastAt":"2006-12-21T18:09:35Z","messageCount":3,"participants":["Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"29955","messageId":"200612211807.54668.jnareb@gmail.com","threadId":"6063","inReplyTo":null,"subject":"gitweb: Version independent mod_perl woes","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-21T17:07:53Z","receivedAt":"2006-12-21T17:07:53Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"I try to make gitweb run under mod_perl without need to set up CGI\nenvironmental variables, and without need to parse headers. I try to do\nthis in such a way that one will be able to run gitweb under mod_cgi\n(as an ordinary CGI script), under mod_perl 1.0 Apache::registry and\nunder mod_perl 2.0 ModPerl::Registry without changes.\n\nI'm trying to do the first part (running without need for SetupEnv),\nbut I'm encountering some strange errors and I'm stumped.\n\nI have taken the version independent initialization from\n  http://perl.apache.org/docs/2.0/user/porting/porting.html#Making_Code_Conditional_on_Running_mod_perl_Version\n\n-- >8 --\n# Set the constant MP_GEN to 0 if mod_perl is not available,\n# to 1 if running under mod_perl 1.0\n# and 2 for mod_perl 2.0\nuse constant MP_GEN => $ENV{'MOD_PERL'}\n\t? { ( exists $ENV{'MOD_PERL_API_VERSION'} and \n\t      $ENV{'MOD_PERL_API_VERSION'} >= 2 ) ? 2 : 1 }\n\t: 0;\n\n# use appropriate mod_perl modules (conditional use)\nBEGIN {\n\tif (MP_GEN == 2) {\n\t\trequire Apache2::RequestRec;\n\t\trequire Apache2::ServerRec;\n\t\trequire Apache2::Response;\n\t\trequire Apache2::Const;\n\t\timport Apache2::RequestRec;\n\t\timport Apache2::ServerRec;\n\t\tApache2::Const->import(-compile => qw(:common :http));\n\t} elsif (MP_GEN == 1) {\n\t\trequire Apache;\n\t\trequire Apache::Constants;\n\t\timport Apache;\n\t\tApache::Constants->import(qw(:common :http));\n\t}\n}\n\n# mod_perl request\nmy $r;\n$r = shift @_ if MP_GEN;\n-- >8 --\n\nThen later I try to use mod_perl rather than $ENV{'SERVER_NAME'}\n\n-- >8 --\n# name of your site or organization to appear in page titles\n# replace this with something more descriptive for clearer bookmarks\nour $site_name = \"++GITWEB_SITENAME++\"\n                 || (($r ? $r->server()->server_hostname() : $ENV{'SERVER_NAME'})\n                     || \"Untitled\") . \" Git\";\n-- >8 --\n\nbut I'm encountering the following error:\n\n  Can't locate object method \"server_hostname\" via package \"Apache2::ServerRec\"\n  at /var/www/perl/gitweb/gitweb.cgi line 83.\n\nWhat is strange from time to time it _works_.\n\n\nCan anyone tell me what I'm doing wrong?\n-- \nJakub Narebski\nPoland\n"},{"id":"29957","messageId":"200612211851.28807.jnareb@gmail.com","threadId":"6063","inReplyTo":"200612211807.54668.jnareb@gmail.com","subject":"Re: gitweb: Version independent mod_perl woes","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-21T17:51:28Z","receivedAt":"2006-12-21T17:51:28Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"> Can anyone tell me what I'm doing wrong?\n\nAh, I forgot to add:\n\nApache 2.0.54 (httpd-2.0.54-10.3)\nmod_perl 2.0.1 (mod_perl-2.0.1-1.fc4)\nPerl 5.8.6 (perl-5.8.6-24)\n\n$Apache2::RequestRec::VERSION = 2.000001\n$Apache2::ServerRec::VERSION  = 2.000001\n\n-- >8 -- [fragment of httpd.conf] ---\nAlias /perl \"/var/www/perl\"\n<Directory \"/var/www/perl\">\n    SetHandler perl-script\n    PerlResponseHandler ModPerl::Registry\n    PerlOptions +ParseHeaders\n    Options Indexes FollowSymlinks +ExecCGI\n    AllowOverride None\n    Order allow,deny\n    Allow from all\n</Directory>\n-- >8 --\n\nP.S. The goal is for gitweb to work with\n    PerlOptions -SetupEnv -ParseHeaders\n-- \nJakub Narebski\nPoland\n"},{"id":"29958","messageId":"200612211909.35615.jnareb@gmail.com","threadId":"6063","inReplyTo":"200612211807.54668.jnareb@gmail.com","subject":"Re: gitweb: Version independent mod_perl woes","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-21T18:09:35Z","receivedAt":"2006-12-21T18:09:35Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Jakub Narebski wrote:\n> -- >8 --\n> # Set the constant MP_GEN to 0 if mod_perl is not available,\n> # to 1 if running under mod_perl 1.0\n> # and 2 for mod_perl 2.0\n> use constant MP_GEN => $ENV{'MOD_PERL'}\n>         ? { ( exists $ENV{'MOD_PERL_API_VERSION'} and \n>               $ENV{'MOD_PERL_API_VERSION'} >= 2 ) ? 2 : 1 }\n>         : 0;\n\nActually, the error was here. It works like expected for\n\n use constant {\n \tMP_GEN => ($ENV{'MOD_PERL'}\n \t           ? ( exists $ENV{'MOD_PERL_API_VERSION'} and \n \t               $ENV{'MOD_PERL_API_VERSION'} >= 2 ) ? 2 : 1\n \t           : 0),\n };\n\n> # use appropriate mod_perl modules (conditional use)\n> BEGIN {\n>         if (MP_GEN == 2) {\n>                 require Apache2::RequestRec;\n>                 require Apache2::ServerRec;\n>                 require Apache2::Response;\n>                 require Apache2::Const;\n>                 import Apache2::RequestRec;\n>                 import Apache2::ServerRec;\n>                 Apache2::Const->import(-compile => qw(:common :http));\n>         } elsif (MP_GEN == 1) {\n>                 require Apache;\n>                 require Apache::Constants;\n>                 import Apache;\n>                 Apache::Constants->import(qw(:common :http));\n>         }\n> }\n> \n> # mod_perl request\n> my $r;\n> $r = shift @_ if MP_GEN;\n> -- >8 --\n\nSorry for the noise.\n-- \nJakub Narebski\nPoland\n"}]}