Author: timbo
Date: Wed May 23 02:50:23 2007
New Revision: 9595

Modified:
   dbi/trunk/lib/DBI/ProfileDumper/Apache.pm
   dbi/trunk/t/41prof_dump.t

Log:
Test that lib/DBI/ProfileDumper/Apache.pm can be loaded outside apache.
If executed outside apache then fallback to using /tmp and give a warning.


Modified: dbi/trunk/lib/DBI/ProfileDumper/Apache.pm
==============================================================================
--- dbi/trunk/lib/DBI/ProfileDumper/Apache.pm   (original)
+++ dbi/trunk/lib/DBI/ProfileDumper/Apache.pm   Wed May 23 02:50:23 2007
@@ -180,16 +180,22 @@
         $path = $ENV{DBI_PROFILE_APACHE_LOG_DIR};
     }
     else {
-        # can't cache, at least not during startup
-        my $subdir = "logs";
-        if (MP2) {
-            require Apache2::RequestUtil;
-            require Apache2::ServerUtil;
-            $path = 
Apache2::ServerUtil::server_root_relative(Apache2::RequestUtil->request()->pool,
 $subdir)
-        }
-        else {
-            require Apache;
-            $path = Apache->server_root_relative($subdir);
+        eval {
+            # can't cache, at least not during startup
+            my $subdir = "logs";
+            if (MP2) {
+                require Apache2::RequestUtil;
+                require Apache2::ServerUtil;
+                $path = 
Apache2::ServerUtil::server_root_relative(Apache2::RequestUtil->request()->pool,
 $subdir)
+            }
+            else {
+                require Apache;
+                $path = Apache->server_root_relative($subdir);
+            }
+        };
+        if ($@) {   # probably due to not running inside Apache
+            $path = "/tmp";
+            warn "Can't determine path for $self (will use $path): $@";
         }
     }
     return $path;

Modified: dbi/trunk/t/41prof_dump.t
==============================================================================
--- dbi/trunk/t/41prof_dump.t   (original)
+++ dbi/trunk/t/41prof_dump.t   Wed May 23 02:50:23 2007
@@ -14,12 +14,12 @@
 use Test::More;
 
 BEGIN {
-       if ($DBI::PurePerl) {
-               plan skip_all => 'profiling not supported for DBI::PurePerl';
-       }
-       else {
-               plan tests => 15;
-       }
+    if ($DBI::PurePerl) {
+        plan skip_all => 'profiling not supported for DBI::PurePerl';
+    }
+    else {
+        plan tests => 16;
+    }
 }
 
 BEGIN {
@@ -83,4 +83,6 @@
 
 # unlink("dbi.prof"); # now done by 'make clean'
 
+require_ok('DBI::ProfileDumper::Apache'); # should be able to load 
DBI::ProfileDumper::Apache outside apache
+
 1;

Reply via email to