diff --git a/lib/Mojo/Server.pm b/lib/Mojo/Server.pm index dd33db8248..6a7d4a9dd9 100644 --- a/lib/Mojo/Server.pm +++ b/lib/Mojo/Server.pm @@ -54,9 +54,11 @@ sub load_app { local @ARGS_OVERRIDE = @args; # Try to load application from script into sandbox - my $app = eval "package Mojo::Server::Sandbox::@{[md5_sum $path]}; do \$path"; - my $err = $app ? undef : $@ || $! || "$path did not return a true value"; - die qq{Can't load application from file "$path": $err} if $err; + my $app = eval sprintf <<'END_CODE', md5_sum($path); + package Mojo::Server::Sandbox::%s; + do $path or die $@ || $! || "$path did not return a true value"; +END_CODE + die qq{Can't load application from file "$path": $@} if $@; die qq{File "$path" did not return an application object.\n} unless blessed $app && $app->can('handler'); $self->app($app); }; diff --git a/t/mojo/daemon.t b/t/mojo/daemon.t index 72b60b6b57..bed421d5d7 100644 --- a/t/mojo/daemon.t +++ b/t/mojo/daemon.t @@ -88,7 +88,8 @@ subtest 'Load broken app' => sub { eval { Mojo::Server::Daemon->new->load_app("$bin/lib/Mojo/LoaderTest/A.pm") }; like $@, qr/did not return an application object/, 'right error'; eval { Mojo::Server::Daemon->new->load_app("$bin/lib/Mojo/LoaderException.pm") }; - like $@, qr/^Can't load application/, 'right error'; + like $@, qr/Missing right curly or square bracket/, 'right error'; + like $@, qr/^Can't load application/, 'right error'; }; subtest 'Load app using module_true' => sub {