my ($self, $env, @args) = @_;
my $next = $self->_has_match ? $self->next : undef;
if (my ($env_delta, @match) = $self->_match_against($env)) {
- if (my ($result) = $self->_execute_with(@args, @match)) {
+ if (my ($result) = $self->_execute_with(@args, @match, $env)) {
if ($self->_is_dispatcher($result)) {
$next = $result->set_next($next);
$env = { %$env, %$env_delta };
my $chain = $class->_build_dispatch_chain(@res);
return $class->_build_dispatcher({
call => sub {
- my ($d, $self, $env) = (shift, shift, shift);
+ my ($d, $self, $env) = (shift, shift, shift); pop; # lose trailing $env
return $chain->dispatch($env, $self, @_);
}
});
});
return $class->_build_dispatcher({
call => sub {
- my ($d, $self, $env) = (shift, shift, shift);
+ my ($d, $self, $env) = (shift, shift, shift); pop; # lose trailing $env
my @sub = $disp->dispatch($env, $self, @_);
return @sub if @sub;
return unless (my $next = $d->next);
my $matcher = (
defined($proto) && length($proto)
? $parser->parse_dispatch_specification($proto)
- : undef
+ : sub { ({}, $_[1]) }
);
return $class->_build_dispatcher({
match => $matcher,
} 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;
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;