Patch to fix homefinding for scripts in deep subdirs
Marcus Ramberg [Sun, 6 Apr 2008 19:42:48 +0000 (19:42 +0000)]
Changes
lib/Catalyst/Utils.pm
t/something/Makefile.PL [new file with mode: 0644]
t/unit_utils_subdir.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index cbfe518..ffb920e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 # This file documents the revision history for Perl extension Catalyst.
 
 5.7013
+        - Fix subdirs for scripts that run in subdirs more than one level deep.
         - Added test and updated docs for handling the Authorization header
           under mod_fastcgi/mod_cgi.
         - Fixed bug in HTTP engine where the connection was not closed properly if the
index 670353f..4e5571e 100644 (file)
@@ -171,8 +171,9 @@ sub home {
                 # clean up relative path:
                 # MyApp/script/.. -> MyApp
 
-                my ($lastdir) = $home->dir_list( -1, 1 );
-                if ( $lastdir eq '..' ) {
+                my $dir;
+                my @dir_list = $home->dir_list();
+                while (($dir = pop(@dir_list)) && $dir eq '..') {
                     $home = dir($home)->parent->parent;
                 }
 
diff --git a/t/something/Makefile.PL b/t/something/Makefile.PL
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/t/unit_utils_subdir.t b/t/unit_utils_subdir.t
new file mode 100644 (file)
index 0000000..83f9f72
--- /dev/null
@@ -0,0 +1,26 @@
+use Test::More tests=>7;
+
+use strict;
+use warnings;
+
+# simulates an entire testapp rooted at t/something
+# except without bothering creating it since its
+# only the -e check on the Makefile.PL that matters
+
+BEGIN { use_ok 'Catalyst::Utils' }
+use FindBin;
+
+$INC{'TestApp.pm'} = "$FindBin::Bin/something/script/foo/../../lib/TestApp.pm";
+my $home = Catalyst::Utils::home('TestApp');
+like($home, qr/t\/something/, "has path TestApp/t/something"); 
+unlike($home, qr/\/script\/foo/, "doesn't have path /script/foo");
+
+$INC{'TestApp.pm'} = "$FindBin::Bin/something/script/foo/bar/../../../lib/TestApp.pm";
+$home = Catalyst::Utils::home('TestApp');
+like($home, qr/t\/something/, "has path TestApp/t/something"); 
+unlike($home, qr/\/script\/foo\/bar/, "doesn't have path /script/foo");
+
+$INC{'TestApp.pm'} = "$FindBin::Bin/something/script/../lib/TestApp.pm";
+$home = Catalyst::Utils::home('TestApp');
+like($home, qr/t\/something/, "has path TestApp/t/something"); 
+unlike($home, qr/\/script\/foo/, "doesn't have path /script/foo");