From 401be9f6a1a8e7f76405c1a07937fa15a6813679 Mon Sep 17 00:00:00 2001 From: biopete Date: Fri, 7 Apr 2006 18:05:02 +0000 Subject: [PATCH] Peter -- uses more standard method for mp1 and mp2 compatibility in BEGIN block Fixed redirect_request so it works. Needs testing on MP1. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@472 48953598-375a-da11-a14b-00016c27c3ee --- lib/Apache/MVC.pm | 51 ++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/Apache/MVC.pm b/lib/Apache/MVC.pm index ddd742b..3fcdaac 100644 --- a/lib/Apache/MVC.pm +++ b/lib/Apache/MVC.pm @@ -14,29 +14,35 @@ __PACKAGE__->mk_accessors( qw( ar ) ); our $MODPERL2; our $modperl_version; +# pjs -- fixed to use standard way from perl.apache.org BEGIN { - eval 'use Apache;'; - if ($@) { - eval 'use mod_perl2; $modperl_version = $mod_perl2::VERSION; '; - if ($@) { - $modperl_version = $Apache2::RequestRec::VERSION; - } - require Apache2::RequestIO; - require Apache2::RequestRec; - require Apache2::RequestUtil; - require APR::URI; - require HTTP::Body; - $MODPERL2 = 1; + #eval 'use Apache;'; # could fuck shit up if you have some file na + # named Apache.pm in your path forex CGI/Apache.pm + $MODPERL2 = ( exists $ENV{MOD_PERL_API_VERSION} and + $ENV{MOD_PERL_API_VERSION} >= 2 ); + if ($MODPERL2) { + eval 'use mod_perl2; $modperl_version = $mod_perl2::VERSION;'; + if ($@) { + $modperl_version = $Apache2::RequestRec::VERSION; + } + require Apache2::RequestIO; + require Apache2::RequestRec; + require Apache2::RequestUtil; + eval 'use Apache2::Const -compile => qw/REDIRECT/;'; # -compile 4 no import + require APR::URI; + require HTTP::Body; } else { - eval ' use mod_perl; '; - require Apache; - require Apache::Request; - $MODPERL2 = 0; - $modperl_version = 1; + eval ' use mod_perl; '; + require Apache; + require Apache::Request; + eval 'use Apache::Constants -compile => qw/REDIRECT/;'; + $modperl_version = 1; } } + + =head1 NAME Apache::MVC - Apache front-end to Maypole @@ -136,11 +142,13 @@ sub parse_args { =cut # FIXME: use headers_in to gather host and other information? -sub redirect_request +# pjs 4-7-06 fixed so it works but did not fix headers_in issue +sub redirect_request { my $r = shift; my $redirect_url = $_[0]; - my $status = "302"; + my $status = $MODPERL2 ? eval 'Apache2::Const::REDIRECT;' : + eval 'Apache::Constants::REDIRECT;'; # why have to eval this? if ($_[1]) { my %args = @_; if ($args{url}) { @@ -154,8 +162,9 @@ sub redirect_request $status = $args{status} if ($args{status}); } - $r->headers_out->set('Status' => $status); - $r->headers_out->set('Location' => $redirect_url); + $r->ar->status($status); + $r->ar->headers_out->set('Location' => $redirect_url); + #$r->output(""); return OK; } -- 2.39.5