Skip to content

Commit

Permalink
simplify home path logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Feb 8, 2015
1 parent c11769c commit 8c66ee4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Perl module Galileo

0.XXX
- Simplify home path logic

0.0038 2015-01-25
- Fixed compatibility with recent Mojolicious
- Bumped dependency to 5.41
Expand Down
24 changes: 7 additions & 17 deletions lib/Galileo.pm
Expand Up @@ -5,10 +5,13 @@ our $VERSION = '0.038';
$VERSION = eval $VERSION;

use File::Basename 'dirname';
use File::Spec;
use File::Spec::Functions qw'rel2abs catdir';
use File::ShareDir 'dist_dir';
use Cwd;

use Mojo::Home;

has db => sub {
my $self = shift;
my $schema_class = $self->config->{db_schema} or die "Unknown DB Schema Class";
Expand All @@ -21,16 +24,15 @@ has db => sub {
return $schema;
};

has home_path => sub {
has home => sub {
my $path = $ENV{GALILEO_HOME} || getcwd;
return File::Spec->rel2abs($path);
return Mojo::Home->new(File::Spec->rel2abs($path));
};

has config_file => sub {
my $self = shift;
return $ENV{GALILEO_CONFIG} if $ENV{GALILEO_CONFIG};

return rel2abs( 'galileo.conf', $self->home_path );
return $self->home->rel_file('galileo.conf');
};

sub load_config {
Expand All @@ -40,7 +42,7 @@ sub load_config {
file => $app->config_file,
default => {
db_schema => 'Galileo::DB::Schema',
db_dsn => 'dbi:SQLite:dbname=' . $app->home->rel_file( 'galileo.db' ),
db_dsn => 'dbi:SQLite:dbname=' . $app->home->rel_file('galileo.db'),
db_username => undef,
db_password => undef,
db_options => { sqlite_unicode => 1 },
Expand Down Expand Up @@ -124,18 +126,6 @@ sub _to_abs {
sub startup {
my $app = shift;

# set home folder
$app->home->parse( $app->home_path );

{
# setup logging path
# code stolen from Mojolicious.pm
my $mode = $app->mode;

$app->log->path($app->home->rel_file("log/$mode.log"))
if -w $app->home->rel_file('log');
}

$app->load_config;

{
Expand Down

0 comments on commit 8c66ee4

Please sign in to comment.