X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FUtils.pm;h=29bef60028e91361dc11ae9e03e9c65820fdda86;hp=b053c6f92c26b2c094a157875c0df67069677a37;hb=d17ae380f89fffa8c458925bfd7c7b0c7be0bc96;hpb=0f519d62e1948c0d56109abc0c419c51a3ba2de5 diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index b053c6f..29bef60 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,42 @@ sub home { return 0; } +=head2 find_home_unloaded_in_checkout ($path) + +Tries to determine if C<$path> (or cwd if not supplied) +looks like a checkout. Any leading lib or blib components +will be removed, then the directory produced will be checked +for the existence of a C<< dist_indicator_file_list() >>. + +If one is found, the directory will be returned, otherwise false. + +=cut + +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.