From: Matt S Trout Date: Sat, 25 Sep 2010 18:05:40 +0000 (+0100) Subject: skeleton CLI support X-Git-Tag: v0.005~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=d104fb1d4629592eebe6a43d7a4481da931f673d skeleton CLI support --- diff --git a/lib/Web/Simple/Application.pm b/lib/Web/Simple/Application.pm index 9511e34..3bdbd97 100644 --- a/lib/Web/Simple/Application.pm +++ b/lib/Web/Simple/Application.pm @@ -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;