Fixed scripts on win32
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Utils.pm
index e1b6440..325e723 100644 (file)
@@ -2,7 +2,9 @@ package Catalyst::Utils;
 
 use strict;
 use attributes ();
+use HTTP::Request;
 use Path::Class;
+use URI;
 
 =head1 NAME
 
@@ -112,7 +114,11 @@ sub home {
         my $subdir = dir($home)->subdir($append);
         for ( split '/', $name ) { $home = dir($home)->parent }
         if ( $home =~ /blib$/ ) { $home = dir($home)->parent }
-        elsif ( !-f file( $home, 'Makefile.PL' ) ) { $home = $subdir }
+        elsif (!-f file( $home, 'Makefile.PL' )
+            && !-f file( $home, 'Build.PL' ) )
+        {
+            $home = $subdir;
+        }
     }
     return $home;
 }
@@ -146,6 +152,32 @@ sub reflect_actions {
     return $actions;
 }
 
+=item request($string);
+
+Returns an C<HTTP::Request> from a string.
+
+=cut
+
+sub request {
+    my $request = shift;
+
+    unless ( ref $request ) {
+
+        if ( $request =~ m/http/i ) {
+            $request = URI->new($request)->canonical;
+        }
+        else {
+            $request = URI->new( 'http://localhost' . $request )->canonical;
+        }
+    }
+
+    unless ( ref $request eq 'HTTP::Request' ) {
+        $request = HTTP::Request->new( 'GET', $request );
+    }
+
+    return $request;
+}
+
 =back
 
 =head1 AUTHOR