Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
try not to resolve the application path
  • Loading branch information
kraih committed Apr 7, 2015
1 parent 49978de commit 7efcb3e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 26 deletions.
23 changes: 10 additions & 13 deletions lib/Mojo/Home.pm
Expand Up @@ -12,24 +12,21 @@ use Mojo::Util 'class_to_path';
has parts => sub { [] };

sub detect {
my $self = shift;
my ($self, $class) = @_;

# Environment variable
return $self->parts([splitdir abs_path $ENV{MOJO_HOME}]) if $ENV{MOJO_HOME};

# Try to find home from lib directory
if (my $class = @_ ? shift : 'Mojo::HelloWorld') {
my $file = class_to_path $class;
if (my $path = $INC{$file}) {
$path =~ s/\Q$file\E$//;
my @home = splitdir $path;

# Remove "lib" and "blib"
pop @home while @home && ($home[-1] =~ /^b?lib$/ || $home[-1] eq '');

# Turn into absolute path
return $self->parts([splitdir abs_path catdir(@home) || '.']);
}
if ($class && (my $path = $INC{my $file = class_to_path $class})) {
$path =~ s/\Q$file\E$//;
my @home = splitdir $path;

# Remove "lib" and "blib"
pop @home while @home && ($home[-1] =~ /^b?lib$/ || $home[-1] eq '');

# Turn into absolute path
return $self->parts([splitdir abs_path catdir(@home) || '.']);
}

# FindBin fallback
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server.pm
Expand Up @@ -2,7 +2,7 @@ package Mojo::Server;
use Mojo::Base 'Mojo::EventEmitter';

use Carp 'croak';
use Cwd 'abs_path';
use File::Spec::Functions 'rel2abs';
use Mojo::Loader 'load_class';
use Mojo::Util 'md5_sum';
use POSIX;
Expand Down Expand Up @@ -44,7 +44,7 @@ sub load_app {

# Clean environment (reset FindBin defensively)
{
local $0 = $path = abs_path $path;
local $0 = $path = rel2abs $path;
require FindBin;
FindBin->again;
local $ENV{MOJO_APP_LOADER} = 1;
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -3,9 +3,8 @@ use Mojo::Base -base;

# "Bender: I was God once.
# God: Yes, I saw. You were doing well, until everyone died."
use Cwd 'abs_path';
use File::Basename 'dirname';
use File::Spec::Functions 'catfile';
use File::Spec::Functions qw(catfile rel2abs);
use Mojo::Server::Prefork;
use Mojo::Util qw(steady_time);
use Scalar::Util 'weaken';
Expand Down Expand Up @@ -40,7 +39,7 @@ sub run {

# Remember executable and application for later
$ENV{HYPNOTOAD_EXE} ||= $0;
$0 = $ENV{HYPNOTOAD_APP} ||= abs_path $app;
$0 = $ENV{HYPNOTOAD_APP} ||= rel2abs $app;

# This is a production server
$ENV{MOJO_MODE} ||= 'production';
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojolicious/Plugin/Config.pm
Expand Up @@ -134,8 +134,9 @@ File extension for generated configuration filenames, defaults to C<conf>.
plugin Config => {file => 'myapp.conf'};
plugin Config => {file => '/etc/foo.stuff'};
Full path to configuration file, defaults to the value of the C<MOJO_CONFIG>
environment variable or C<$moniker.conf> in the application home directory.
Path to configuration file, absolute or relative to the application home
directory, defaults to the value of the C<MOJO_CONFIG> environment variable or
C<$moniker.conf> in the application home directory.
=head1 METHODS
Expand Down
3 changes: 1 addition & 2 deletions t/mojo/daemon.t
Expand Up @@ -3,7 +3,6 @@ use Mojo::Base -strict;
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::More;
use Cwd 'abs_path';
use File::Spec::Functions 'catdir';
use FindBin;
use Mojo;
Expand Down Expand Up @@ -82,7 +81,7 @@ is_deeply $app->config, {foo => 'bar', baz => 'yada', test => 23},
# Script name
my $path = "$FindBin::Bin/lib/../lib/myapp.pl";
is(Mojo::Server::Daemon->new->load_app($path)->config('script'),
abs_path($path), 'right script name');
$path, 'right script name');

# Load broken app
eval {
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/home.t
Expand Up @@ -19,7 +19,7 @@ use Mojo::Home;
}

# Class detection
my $original = catdir(splitdir($FindBin::Bin), '..', '..');
my $original = catdir splitdir $FindBin::Bin;
my $home = Mojo::Home->new->detect;
my $target = realpath $original;
is_deeply [split /\\|\//, $target], [split /\\|\//, $home],
Expand Down
6 changes: 3 additions & 3 deletions t/mojolicious/json_config_lite_app.t
Expand Up @@ -17,16 +17,16 @@ app->config(it => 'works');
is_deeply app->config, {it => 'works'}, 'right value';

# Invalid config file
my $path = abs_path catfile(dirname(__FILE__), 'public', 'hello.txt');
eval { plugin JSONConfig => {file => $path}; };
eval { plugin JSONConfig => {file => 'public/hello.txt'} };
like $@, qr/Malformed JSON/, 'right error';

# Load plugins
my $config
= plugin j_s_o_n_config => {default => {foo => 'baz', hello => 'there'}};
my $log = '';
my $cb = app->log->on(message => sub { $log .= pop });
$path = abs_path catfile(dirname(__FILE__), 'json_config_lite_app_abs.json');
my $path
= abs_path catfile(dirname(__FILE__), 'json_config_lite_app_abs.json');
plugin JSONConfig => {file => $path};
like $log, qr/Reading configuration file "\Q$path\E"/, 'right message';
app->log->unsubscribe(message => $cb);
Expand Down

0 comments on commit 7efcb3e

Please sign in to comment.