Skip to content

Commit

Permalink
Build system config dir into Config.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Apr 30, 2012
1 parent fd2a7ce commit bf00ff9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/App/Sqitch/Config.pm
Expand Up @@ -4,7 +4,6 @@ use v5.10.1;
use Moose;
use strict;
use warnings;
use Config;
use Path::Class;
use Carp;
use utf8;
Expand All @@ -17,6 +16,8 @@ has '+confname' => (
default => 'sqitch.conf',
);

my $SYSTEM_DIR = undef;

sub user_dir {
require File::HomeDir;
my $hd = File::HomeDir->my_home or croak(
Expand All @@ -26,7 +27,10 @@ sub user_dir {
}

sub system_dir {
dir $Config{prefix}, 'etc', 'sqitch';
dir $SYSTEM_DIR || do {
require Config;
$Config::Config{prefix}, 'etc', 'sqitch';
};
}

sub system_file {
Expand Down
16 changes: 16 additions & 0 deletions priv/Module/Build/Sqitch.pm
Expand Up @@ -37,4 +37,20 @@ sub process_etc_files {
}
}

sub process_pm_files {
my $self = shift;
my $ret = $self->SUPER::process_pm_files(@_);
my $pm = File::Spec->catfile(qw(blib lib App Sqitch Config.pm));
my $etc = $self->_path_to('etc');

$self->do_system(
$self->perl,
'-i', '-pe',
qq{s{my \\\$SYSTEM_DIR = undef}{my \\\$SYSTEM_DIR = q{$etc}}},
$pm,
);

return $ret;
}

1;
2 changes: 1 addition & 1 deletion t/add_step.t
Expand Up @@ -141,7 +141,7 @@ is $add_step->template_directory, undef, 'Default dir should be undef';

MOCKCONFIG: {
my $config_mock = Test::MockModule->new('App::Sqitch::Config');
$config_mock->mock(system_dir => 'nonexistent');
$config_mock->mock(system_dir => Path::Class::dir('nonexistent'));
for my $script (qw(deploy revert test)) {
my $with = "with_$script";
ok $add_step->$with, "$with should be true by default";
Expand Down

0 comments on commit bf00ff9

Please sign in to comment.