X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FWeb%2FSimple%2FApplication.pm;h=7ef273b1f6dd4f0fa81a930dfcb86039ff0e6ff3;hb=7346dbd367858f693d12a0180ee391b12cc8347a;hp=f72142a20e413266c29cde3bdf461ae8bc097049;hpb=fd8747e504c32074e49b1514b39418c32bd22a32;p=catagits%2FWeb-Simple.git diff --git a/lib/Web/Simple/Application.pm b/lib/Web/Simple/Application.pm index f72142a..7ef273b 100644 --- a/lib/Web/Simple/Application.pm +++ b/lib/Web/Simple/Application.pm @@ -1,6 +1,7 @@ package Web::Simple::Application; use Scalar::Util 'weaken'; +use Try::Tiny; use Moo; @@ -49,12 +50,22 @@ sub _build_final_dispatcher { } sub run_if_script { + my ( $self ) = @_; # ->to_psgi_app is true for require() but also works for plackup - return $_[0]->to_psgi_app if caller(1); - my $self = ref($_[0]) ? $_[0] : $_[0]->new; + return $self->to_psgi_app if caller(1); + $self = ref($self) ? $self : $self->_build_for_run_if_script; $self->run(@_); } +sub _build_for_run_if_script { + my ( $self ) = @_; + try { $self->new } + catch { + die "Failed to create new '$self' object during run_if_script" + . " (should your .pm file end with just '1;'?) : $_\n"; + }; +} + sub _run_cgi { my $self = shift; require Plack::Handler::CGI;