my $proto = prototype $spec;
my $parser = $class->_build_dispatch_parser;
my $matcher = (
- defined($proto)
+ defined($proto) && length($proto)
? $parser->parse_dispatch_specification($proto)
: undef
);
shift->_build_dispatcher({
call => sub {
[
- 500, [ 'Content-type', 'text/plain' ],
- [ 'The management apologises but we have no idea how to handle that' ]
+ 404, [ 'Content-type', 'text/plain' ],
+ [ 'Not found' ]
]
}
})
}
sub run_if_script {
- return 1 if caller(1); # 1 so we can be the last thing in the file
+ # ->as_psgi_app is true for require() but also works for plackup
+ return $_[0]->as_psgi_app if caller(1);
my $class = shift;
my $self = $class->new;
$self->run(@_);
sub _run_cgi {
my $self = shift;
require Web::Simple::HackedPlack;
- Plack::Server::CGI->run(sub { $self->_dispatch(@_) });
+ Plack::Server::CGI->run($self->as_psgi_app);
+}
+
+sub as_psgi_app {
+ my $self = shift;
+ ref($self) ? sub { $self->_dispatch(@_) } : sub { $self->new->_dispatch(@_) }
}
sub run {