Skip to content

Commit

Permalink
handle app function consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 1, 2013
1 parent 36da6b8 commit 86f46c8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Mojolicious/Command/eval.pm
Expand Up @@ -25,7 +25,7 @@ sub run {
# Run code against application
my $app = $self->app;
no warnings;
my $result = eval "package main; sub app { \$app }; $code";
my $result = eval "package main; sub app; local *app = sub { \$app }; $code";
return $@ ? die $@ : $result unless defined $result && ($v1 || $v2);
$v2 ? print($app->dumper($result)) : say $result;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Plugin/Config.pm
Expand Up @@ -14,8 +14,9 @@ sub parse {
my ($self, $content, $file, $conf, $app) = @_;

# Run Perl code
my $config = eval 'package Mojolicious::Plugin::Config::Sandbox;'
. "no warnings; sub app { \$app }; use Mojo::Base -strict; $content";
my $config
= eval 'package Mojolicious::Plugin::Config::Sandbox; no warnings;'
. "sub app; local *app = sub { \$app }; use Mojo::Base -strict; $content";
die qq{Couldn't load configuration from file "$file": $@} if !$config && $@;
die qq{Config file "$file" did not return a hash reference.\n}
unless ref $config eq 'HASH';
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/JSONConfig.pm
Expand Up @@ -24,7 +24,7 @@ sub render {

# Application instance and helper
my $prepend = q[my $app = shift; no strict 'refs'; no warnings 'redefine';];
$prepend .= q[sub app; *app = sub { $app }; use Mojo::Base -strict;];
$prepend .= q[sub app; local *app = sub { $app }; use Mojo::Base -strict;];

# Render and encode for JSON decoding
my $mt = Mojo::Template->new($conf->{template} || {})->name($file);
Expand Down

0 comments on commit 86f46c8

Please sign in to comment.