Skip to content

[Feature request] lookup_config_file to return all config files, not the first found one #27

@van-de-bugger

Description

@van-de-bugger

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions