From: Marcus Ramberg Date: Sun, 6 Apr 2008 19:42:48 +0000 (+0000) Subject: Patch to fix homefinding for scripts in deep subdirs X-Git-Tag: 5.7099_04~87 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e9902daeaa20fcd6a3dc8fcb53407dbe7a6fd761 Patch to fix homefinding for scripts in deep subdirs --- diff --git a/Changes b/Changes index cbfe518..ffb920e 100644 --- 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 diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 670353f..4e5571e 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -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 index 0000000..e69de29 diff --git a/t/unit_utils_subdir.t b/t/unit_utils_subdir.t new file mode 100644 index 0000000..83f9f72 --- /dev/null +++ b/t/unit_utils_subdir.t @@ -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");