prepared for 03
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Utils.pm
index dae3439..9e389e3 100644 (file)
@@ -165,8 +165,18 @@ sub home {
             $home = $home->parent while $home =~ /b?lib$/;
 
             # only return the dir if it has a Makefile.PL or Build.PL
-            return $home->stringify
-                if $home->file("Makefile.PL") or -f $home->file("Build.PL");
+            if (-f $home->file("Makefile.PL") or -f $home->file("Build.PL")) {
+
+                # clean up relative path:
+                # MyApp/script/.. -> MyApp
+
+                my ($lastdir) = $home->dir_list( -1, 1 );
+                if ( $lastdir eq '..' ) {
+                    $home = dir($home)->parent->parent;
+                }
+
+                return $home->stringify;
+            }
         }
 
         {
@@ -230,8 +240,10 @@ Loads the class unless it already has been loaded.
 
 sub ensure_class_loaded {
     my $class = shift;
+    my $opts  = shift;
 
-    return if Class::Inspector->loaded( $class ); # if a symbol entry exists we don't load again
+    return if !$opts->{ ignore_loaded }
+        && Class::Inspector->loaded( $class ); # if a symbol entry exists we don't load again
 
     # this hack is so we don't overwrite $@ if the load did not generate an error
     my $error;