-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
lookup_config_file returns the first found config file. Sometimes such behavior is not convenient. For example, a config file ~/.config/app/app.conf may define an app configuration only partially, and global config file /etc/xdg/app/app.conf is still required to get settings, not defined in the ~/.config/app/app.conf. It would be nice if lookup_config_file returns not only the first found file, but all found files.
A possible implementation is trivial:
sub _lookup_file {
my ($self, $type, @subpath) = @_;
Carp::croak('subpath not specified') unless @subpath;
Carp::croak("invalid type: $type") unless defined $self->{$type};
my @dirs = ($self->{$type}, split(/\Q$Config{path_sep}\E/, $self->_dirs($type)));
my @paths = map { $self->_file($_, @subpath) } @dirs;
my ($match) = grep { -f $_ } @paths;
return $match;
}
The two last lines of the function should be:
my @match = grep { -f $_ } @paths;
return wantarray ? @match : $match[ 0 ];
Alternatively, it could be a set of new functions like lookup_config_files or lookup_all_config_files, if you don't like context-sensitive functions.
Metadata
Metadata
Assignees
Labels
No labels