stas 2004/03/24 11:59:41
Modified: lib/Apache Status.pm
. Changes
Log:
Fix Apache::Status, to lookup the Apache::Request version without
loading it. Only if a suitable (2.x) version is found -- load and use
it. Previously loading the 1.x version was affecting Apache::compat.
Revision Changes Path
1.23 +67 -21 modperl-2.0/lib/Apache/Status.pm
Index: Status.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/Status.pm,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -u -r1.22 -r1.23
--- Status.pm 23 Mar 2004 02:34:19 -0000 1.22
+++ Status.pm 24 Mar 2004 19:59:41 -0000 1.23
@@ -23,6 +23,9 @@
use Apache::RequestRec ();
use Apache::RequestUtil ();
use Apache::ServerUtil ();
+
+use File::Spec ();
+
use Apache::Const -compile => qw(OK);
$Apache::Status::VERSION = '3.00'; # mod_perl 2.0
@@ -31,28 +34,11 @@
our $newQ;
-if (eval { require Apache::Request }) {
- if ($Apache::Request::VERSION >= 2) {
- $newQ ||= sub { Apache::Request->new(@_) };
- }
-}
-else {
- if ($@ !~ m|^Can't locate Apache/Request.pm|) {
- # we hit Apache::Request from mp1 which has failed to load
- # because it couldn't load other things, but it left all kind
- # of things behind, that will affect other code (e.g. magical
- # Apache::Table in %INC), so try to undo the damage
- # otherwise loading Apache::compat which calls:
- # $INC{'Apache/Table.pm'} = __FILE__;
- # crashes
- delete $INC{"Apache/Table.pm"};
- delete $INC{"Apache/Request.pm"};
- }
- else {
- # user has no Apache::Request installed
- }
+if (parse_version("Apache::Request") > 2 &&
+ eval { require Apache::Request }) {
+ $newQ ||= sub { Apache::Request->new(@_) };
}
-if (!$newQ && eval { require CGI }) {
+elsif (eval { require CGI }) {
if ($CGI::VERSION >= 2.93) {
$newQ ||= sub { CGI->new(@_) };
}
@@ -855,6 +841,66 @@
else {
return Config::myconfig();
}
+}
+
+# mp2 modules have to deal with situations where a binary incompatible
+# mp1 version of the same module is installed in the same
+# tree. therefore when checking for a certain version, one wants to
+# check the version of the module 'require()' will find without
+# loading that module. this function partially adopted from
+# ExtUtils::MM_Unix does just that. it returns the version number of
+# the first module that it finds, forcing numerical context, making
+# the return value suitable for immediate numerical comparison
+# operation. (i.e. 2.03-dev will be returned as 2.03, 0 will be
+# returned when the parsing has failed or a module wasn't found).
+sub parse_version {
+ my $name = shift;
+ die "no module name passed" unless $name;
+ my $file = File::Spec->catfile(split /::/, $name) . '.pm';
+ for my $dir (@INC) {
+ next if ref $dir; # skip code refs
+
+ my $pmfile = File::Spec->catfile($dir, $file);
+ next unless -r $pmfile;
+
+ open my $fh, $pmfile or die "can't open $pmfile: $!";
+
+ my $inpod = 0;
+ my $version;
+ while (<$fh>) {
+ $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
+ next if $inpod || /^\s*#/;
+
+ chomp;
+ next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
+ { local($1, $2); ($_ = $_) = /(.*)/; } # untaint
+ my $eval = qq{
+ package ModPerl::Util::_version;
+ no strict;
+
+ local $1$2;
+ \$$2=undef; do {
+ $_
+ }; \$$2
+ };
+ no warnings;
+ $version = eval $eval;
+ warn "Could not eval '$eval' in $pmfile: $@" if $@;
+ last;
+ }
+
+ close $fh;
+
+ # avoid situations like "2.03-dev" and return a numerical
+ # version
+ if (defined $version) {
+ no warnings;
+ $version += 0; # force number
+ return $version;
+ }
+ }
+
+ return 0; # didn't find the file or the version number
}
1;
1.351 +4 -3 modperl-2.0/Changes
Index: Changes
===================================================================
RCS file: /home/cvs/modperl-2.0/Changes,v
retrieving revision 1.350
retrieving revision 1.351
diff -u -u -r1.350 -r1.351
--- Changes 23 Mar 2004 02:34:19 -0000 1.350
+++ Changes 24 Mar 2004 19:59:41 -0000 1.351
@@ -12,9 +12,10 @@
=item 1.99_14-dev
-Fix Apache::Status, to gracefully recover from failing to load
-Apache::Request when mp1's version is found. Previously it was
-affecting Apache::compat [Stas]
+Fix Apache::Status, to lookup the Apache::Request version without
+loading it. Only if a suitable (2.x) version is found -- load and use
+it. Previously loading the 1.x version was affecting Apache::compat.
+[Stas]
Fix a bug in special blocks handling (like END), which until now was
dropping on the floor all blocks but the last one (mainly affecting