#!/usr/bin/env perl
########################################################################
# Locate the nearest etc/app.conf walking up from the program's
# directory, with one FindBin::Files call.  See POD.
########################################################################

use v5.40;

use FindBin::Bin    qw( $Bin_p );

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

$app_conf
or die "No etc/app.conf in any directory above '$Bin_p'.\n";

say "Config: $app_conf";

__END__

=head1 NAME

find_app_conf - locate the nearest etc/app.conf

=head1 SYNOPSIS

    find_app_conf

=head1 DESCRIPTION

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

Checks C<etc/app.conf> under each directory from C<$Bin_p> up to the
root, and exports the nearest one as C<$app_conf>, or C<''> if there
is none.  Without C<scalar> it exports C<@app_conf>, every match,
nearest first (see F<example/merge_app_conf>).

C<nofail> leaves the error to the program, which can say what it
expected; without it FindBin::Files carps when nothing is found.

For a program in C</opt/myapp/bin>:

    /opt/myapp/bin/etc/app.conf
    /opt/myapp/etc/app.conf         <- nearest that exists
    /opt/etc/app.conf

C</etc/app.conf> is not checked: the default C<ignore=/,/usr>
skips the root, and C</usr> for programs installed below it.  Pass
C<ignore=> to search every parent.

=head2 Compared with FindBin::libs

F<example/multi_config_dir> does the same with FindBin::libs: export
every C<etc> dir, then test each for the file.  FindBin::Files tests
for the file itself, so an C<etc> dir without one is passed over.

FindBin::libs checks the directories it adds to C<@INC> with
L<File::Util::SecureDir>; FindBin::Files does not check anything.
If the configuration can change what the program runs, check the file
and its directory before reading it.

=head1 SEE ALSO

L<FindBin::Files>, F<example/find_prog_conf>,
F<example/merge_app_conf>, F<example/multi_config_dir>
