#!/usr/bin/env perl
########################################################################
# Locate the first config file named "LocalPaths.conf" in the etc
# dirs found walking up from $FindBin::Bin.  See POD.
########################################################################

use v5.40;

use List::Util      qw( first );

use FindBin::Bin    qw( $Bin_p );

use FindBin::libs   qw( base=etc export nofail );

my $base    = 'LocalPaths.conf';

my $found   = first { -e "$_/$base" } @etc
or die "No '$base' in any etc directory above '$Bin_p'.\n";

say "Config: $found/$base";

__END__

=head1 NAME

multi_config_dir - locate the first etc dir holding LocalPaths.conf

=head1 SYNOPSIS

    multi_config_dir

=head1 DESCRIPTION

    use FindBin::libs qw( base=etc export nofail );

    my $found = first { -e "$_/$base" } @etc;

FindBin::libs exports C<@etc>, every C<etc> dir from C<$Bin_p> up to
the root, nearest first; C<first> returns the nearest one that holds
C<LocalPaths.conf>.  An C<etc> dir without the file is passed over, so
the file can be kept in one shared C<etc> while nearer ones hold other
configuration.

F<example/find_app_conf> does the same with one FindBin::Files call,
which tests for the file itself:

    use FindBin::Files qw( file=etc/LocalPaths.conf scalar nofail );

Neither checks the C<etc> dirs with L<File::Util::SecureDir>:
FindBin::libs checks only the dirs it adds to C<@INC>, not the ones it
exports.

=head1 SEE ALSO

L<FindBin::libs>, F<example/find_app_conf>,
F<example/single_config_dir>
