if (ModPerl::Util::parse_version("Apache::Request") > 2 &&
eval { require Apache::Request }) {
# use Apache::Request
}
else {
# use something else
}you don't need to check for defined, nor to force numerical context for cases like '2.03-dev'. it gives you a good number to use.
notice that 'use Apache::Request 2.0' doesn't work, because it may load an old mp1 version which is not binary compatible. and as it's in case of Apache::Status, we don't want to die if Apache::Request version wasn't satisfied, and CGI.pm is available.
Unless you have better ideas, I'll go ahead and commit this new function and use it in Apache::Status which is currently somewhat broken because of that.
--- /dev/null 1969-12-31 16:00:00.000000000 -0800
+++ xs/ModPerl/Util/Util_pm 2004-03-23 18:32:48.797050343 -0800
@@ -0,0 +1,62 @@
+use File::Spec ();
+
+# 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 $parsefile: $@" 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
+}-- __________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
