skeleton CLI support
Matt S Trout [Sat, 25 Sep 2010 18:05:40 +0000 (19:05 +0100)]
lib/Web/Simple/Application.pm

index 9511e34..3bdbd97 100644 (file)
@@ -271,7 +271,11 @@ sub run {
   } elsif ($ENV{GATEWAY_INTERFACE}) {
     return $self->_run_cgi;
   }
-  my $path = shift(@ARGV) or die "No path passed - use $0 / for root";
+  unless (@ARGV && $ARGV[0] =~ m{^/}) {
+    return $self->_run_cli;
+  }
+
+  my $path = shift @ARGV;
 
   require HTTP::Request::Common;
   require Plack::Test;
@@ -283,4 +287,16 @@ sub run {
   print $response->as_string;
 }
 
+sub _run_cli {
+  my $self = shift;
+  die $self->_cli_usage;
+}
+
+sub _cli_usage {
+  "To run this script in CGI test mode, pass a URL path beginning with /:\n".
+  "\n".
+  "  $0 /some/path\n".
+  "  $0 /\n"
+}
+
 1;