Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small optimizations
  • Loading branch information
kraih committed May 5, 2012
1 parent bcc4b48 commit 7d20c86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 3 additions & 5 deletions lib/Mojo/Server.pm
Expand Up @@ -33,11 +33,9 @@ sub load_app {
# Try to load application from script into sandbox
my $app = eval <<EOF;
package Mojo::Server::SandBox::@{[md5_sum($file . $$)]};
{
my \$app = do \$file;
if (!\$app && (my \$e = \$@ || \$!)) { die \$e }
return \$app;
}
my \$app = do \$file;
if (!\$app && (my \$e = \$@ || \$!)) { die \$e }
\$app;
EOF
die qq/Couldn't load application from file "$file": $@/ if !$app && $@;
die qq/File "$file" did not return an application object.\n/
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/Config.pm
Expand Up @@ -24,7 +24,7 @@ sub parse {

# Run Perl code
my $config = eval 'package Mojolicious::Plugin::Config::Sandbox;'
. "{ no warnings; sub app { \$app }; use Mojo::Base -strict; $content }";
. "no warnings; sub app { \$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
14 changes: 7 additions & 7 deletions lib/Mojolicious/Plugin/I18N.pm
Expand Up @@ -11,16 +11,16 @@ sub register {
my ($self, $app, $conf) = @_;

# Initialize
my $name = $conf->{namespace} || ((ref $app) . "::I18N");
my $default = $conf->{default} || 'en';
die qq/Couldn't initialize I18N class "$name": $@/
unless eval "package $name; { use base 'Locale::Maketext'; 1 }";
my $dc = "${name}::$default";
my $namespace = $conf->{namespace} || ((ref $app) . "::I18N");
my $default = $conf->{default} || 'en';
die qq/Couldn't initialize I18N class "$namespace": $@/
unless eval "package $namespace; use base 'Locale::Maketext'; 1";
my $dc = "${namespace}::$default";
if (my $e = Mojo::Loader->load($dc)) {
die qq/Couldn't load default lexicon class "$dc": $e/ if ref $e;
die qq/Couldn't initialize default lexicon class "$dc": $@/
unless eval
"package $dc; { use base '$name'; our \%Lexicon = (_AUTO => 1); }";
"package $dc; use base '$namespace'; our \%Lexicon = (_AUTO => 1);";
}

# Add hook
Expand All @@ -37,7 +37,7 @@ sub register {

# Handler
$self->stash->{i18n}
= Mojolicious::Plugin::I18N::_Handler->new(namespace => $name);
= Mojolicious::Plugin::I18N::_Handler->new(namespace => $namespace);

# Languages
$self->stash->{i18n}->languages(@languages, $default);
Expand Down

0 comments on commit 7d20c86

Please sign in to comment.