From: Matt S Trout Date: Fri, 27 Nov 2009 02:48:57 +0000 (+0000) Subject: add as_psgi_app and make run_if_script return it for plackup X-Git-Tag: v0.003~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=d3a6160961a582183cfc02efc5e0a09039bd10dd;hp=93e30ba3c4409bccc1a8deb483acab6a8e3fc8c4 add as_psgi_app and make run_if_script return it for plackup --- diff --git a/lib/Web/Simple/Application.pm b/lib/Web/Simple/Application.pm index c00c50c..70339fa 100644 --- a/lib/Web/Simple/Application.pm +++ b/lib/Web/Simple/Application.pm @@ -223,7 +223,8 @@ sub _run_with_self { } 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(@_); @@ -232,7 +233,12 @@ sub run_if_script { 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 {