From: Tomas Doran Date: Thu, 16 Feb 2012 21:09:56 +0000 (+0000) Subject: Split out into new function X-Git-Tag: 5.90010~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=03fb1beee6216e3244e466af11b959694717145f Split out into new function --- diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index b053c6f..020ebc9 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -169,6 +169,8 @@ sub dist_indicator_file_list { Returns home directory for given class. +Note that the class must be loaded for the home directory to be found using this function. + =cut sub home { @@ -183,26 +185,8 @@ 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 - $home = $home->parent while $home =~ /b?lib$/; - - # only return the dir if it has a Makefile.PL or Build.PL or dist.ini - if (any { $_ } map { -f $home->file($_) } dist_indicator_file_list()) { - - # clean up relative path: - # MyApp/script/.. -> MyApp - - my $dir; - my @dir_list = $home->dir_list(); - while (($dir = pop(@dir_list)) && $dir eq '..') { - $home = dir($home)->parent->parent; - } - - return $home->stringify; - } + my $home = find_home_unloaded_in_checkout($path); + return $home if $home; } { @@ -221,6 +205,31 @@ sub home { return 0; } +sub find_home_unloaded_in_checkout { + my ($path) = @_; + $path ||= cwd() if !defined $path || !length $path; + my $home = dir($path)->absolute->cleanup; + + # pop off /lib and /blib if they're there + $home = $home->parent while $home =~ /b?lib$/; + + # only return the dir if it has a Makefile.PL or Build.PL or dist.ini + if (any { $_ } map { -f $home->file($_) } dist_indicator_file_list()) { + + # clean up relative path: + # MyApp/script/.. -> MyApp + + my $dir; + my @dir_list = $home->dir_list(); + while (($dir = pop(@dir_list)) && $dir eq '..') { + $home = dir($home)->parent->parent; + } + + return $home->stringify; + } + +} + =head2 prefix($class, $name); Returns a prefixed action.