App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/Config.pm view on Meta::CPAN
}
sub system_file {
my $self = shift;
return file $ENV{SQITCH_SYSTEM_CONFIG}
|| $self->system_dir->file( $self->confname );
}
sub global_file { shift->system_file }
sub user_file {
my $self = shift;
return file $ENV{SQITCH_USER_CONFIG}
|| $self->user_dir->file( $self->confname );
}
sub local_file {
return file $ENV{SQITCH_CONFIG} if $ENV{SQITCH_CONFIG};
return file shift->confname;
}
sub dir_file { shift->local_file }
# Section keys always have the top section lowercase, and subsections are
# left as-is.
sub _skey($) {
my $key = shift // return '';
my ($sec, $sub, $name) = Config::GitLike::_split_key($key);
return lc $key unless $sec;
return lc($sec) . '.' . join '.', grep { defined } $sub, $name;
}
sub get_section {
my ( $self, %p ) = @_;
$self->load unless $self->is_loaded;
my $section = _skey $p{section};
my $data = $self->data;
return {
map {
( split /[.]/ => $self->initial_key("$section.$_") )[-1],
$data->{"$section.$_"}
}
grep { s{^\Q$section.\E([^.]+)$}{$1} } keys %{$data}
};
}
sub initial_key {
my $key = shift->original_key(shift);
return ref $key ? $key->[0] : $key;
}
sub initialized {
my $self = shift;
$self->load unless $self->is_loaded;
return $self->{_initialized};
}
sub load_dirs {
my $self = shift;
local $self->{__loading_dirs} = 1;
$self->SUPER::load_dirs(@_);
}
sub load_file {
my $self = shift;
$self->{_initialized} ||= $self->{__loading_dirs};
$self->SUPER::load_file(@_);
}
1;
=head1 Name
App::Sqitch::Config - Sqitch configuration management
=head1 Synopsis
my $config = App::Sqitch::Config->new;
say scalar $config->dump;
=head1 Description
This class provides the interface to Sqitch configuration. It inherits from
L<Config::GitLike>, and therefore provides the complete interface of that
module.
=head1 Interface
=head2 Class Methods
=head3 C<home_dir>
my $hd = App::Sqitch->home_dir;
Returns the likely path to the user's hone directory.
=head3 C<user_dir>
Returns the path to the user configuration directory, which is F<~/.sqitch/>.
=head3 C<system_dir>
Returns the path to the system configuration directory, which is
F<$(prefix)/etc/sqitch/templates>. Call C<sqitch --etc-path> to find out
where, exactly (e.g., C<$(sqitch --etc-path)/sqitch.plan>).
=head2 Instance Methods
=head3 C<confname>
Returns the configuration file base name, which is F<sqitch.conf>.
=head3 C<system_file>
Returns the path to the system configuration file. The value returned will be
the contents of the C<$SQITCH_SYSTEM_CONFIG> environment variable, if it's
defined, or else F<$(prefix)/etc/sqitch/templates>. Call C<sqitch --etc-path>
to find out where, exactly (e.g., C<$(sqitch --etc-path)/sqitch.plan>).
=head3 C<global_file>
An alias for C<system_file()> for use by the parent class.
=head3 C<user_file>
Returns the path to the user configuration file. The value returned will be
the contents of the C<$SQITCH_USER_CONFIG> environment variable, if it's
( run in 1.228 second using v1.01-cache-2.11-cpan-5a3173703d6 )