Skip to content

Commit

Permalink
simplify application loading
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 14, 2014
1 parent bc7ff7a commit 961741a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

5.29 2014-08-14
5.29 2014-08-15

5.28 2014-08-13
- Improved performance of nested helpers and helpers in templates
Expand Down
8 changes: 2 additions & 6 deletions lib/Mojo/Server.pm
Expand Up @@ -50,12 +50,8 @@ sub load_app {
local $ENV{MOJO_EXE};

# Try to load application from script into sandbox
my $app = eval sprintf <<'EOF', md5_sum($path . $$);
package Mojo::Server::SandBox::%s;
my $app = do $path;
if (!$app && (my $e = $@ || $!)) { die $e }
$app;
EOF
my $app = eval "package Mojo::Server::Sandbox::@{[md5_sum $path]};"
. 'return do($path) || die($@ || $!);';
die qq{Couldn't load application from file "$path": $@} if !$app && $@;
die qq{File "$path" did not return an application object.\n}
unless blessed $app && $app->isa('Mojo');
Expand Down
8 changes: 8 additions & 0 deletions t/mojo/daemon.t
Expand Up @@ -7,6 +7,7 @@ BEGIN {

use Test::More;
use File::Spec::Functions 'catdir';
use FindBin;
use Mojo;
use Mojo::IOLoop;
use Mojo::Log;
Expand Down Expand Up @@ -61,6 +62,13 @@ is $app->config({test => 23})->config->{test}, 23, 'right value';
is_deeply $app->config, {foo => 'bar', baz => 'yada', test => 23},
'right value';

# Load broken app
eval {
Mojo::Server::Daemon->new->load_app(
"$FindBin::Bin/lib/Mojo/LoaderException.pm");
};
like $@, qr/^Couldn't load application/, 'right error';

# Transaction
isa_ok $app->build_tx, 'Mojo::Transaction::HTTP', 'right class';

Expand Down

0 comments on commit 961741a

Please sign in to comment.