Fix Catalyst::Utils::home() when application .pm is in the current dir (RT #34437)
Brian Cassidy [Tue, 27 May 2008 02:42:11 +0000 (02:42 +0000)]
Changes
lib/Catalyst/Utils.pm
t/unit_utils_subdir.t

diff --git a/Changes b/Changes
index 0586ebb..b826322 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@
 
 5.7xxx  xxx
         - Get some of the optional_* tests working from dirs with spaces (RT #26455)
+        - Fix Catalyst::Utils::home() when application .pm is in the current dir (RT #34437)
 
 5.7014  2008-05-25 15:26:00
         - Addition of .conf in restart regex in Catalyst::Engine::HTTP::Restarter::Watcher
index 4e5571e..2c57244 100644 (file)
@@ -8,6 +8,7 @@ use Path::Class;
 use URI;
 use Class::Inspector;
 use Carp qw/croak/;
+use Cwd;
 
 =head1 NAME
 
@@ -160,6 +161,7 @@ sub home {
 
             # find the @INC entry in which $file was found
             (my $path = $inc_entry) =~ s/$file$//;
+            $path ||= cwd() if !defined $path || !length $path;
             my $home = dir($path)->absolute->cleanup;
 
             # pop off /lib and /blib if they're there
index 8509bea..d35cac0 100644 (file)
@@ -1,4 +1,4 @@
-use Test::More tests=>7;
+use Test::More tests => 8;
 
 use strict;
 use warnings;
@@ -30,3 +30,13 @@ use FindBin;
     like($home, qr{t[\/\\]something}, "has path TestApp/t/something"); 
     unlike($home, qr{[\/\\]script[\/\\]foo}, "doesn't have path /script/foo");
 }
+
+{
+    $INC{'TestApp.pm'} = "TestApp.pm";
+    my $dir = "$FindBin::Bin/something";
+    chdir( $dir );
+  
+    my $home = Catalyst::Utils::home('TestApp');
+
+    is( $home, $dir, 'same dir loading' );
+}