#!/usr/bin/env perl
########################################################################
# Locate the first "etc" dir walking up from $FindBin::Bin, store its
# path into $conf_dir, and use <program name>.conf from it.
#
# Note that if ./t/etc exists this can be used to put test-specific
# config files in ./t, keeping them separate from "real" configs.
########################################################################

use v5.40;

use File::Basename  qw( basename );

use FindBin::Bin    qw( $Bin_p );

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

$conf_dir
or die "No etc directory above '$Bin_p'.\n";

my $base    = basename $0;
my $path    = "$conf_dir/$base.conf";

-e $path    or die "Missing config file: '$path'.\n";

say "Config: $path";

__END__

=head1 NAME

single_config_dir - use <program name>.conf from the nearest etc dir

=head1 SYNOPSIS

    single_config_dir

=head1 DESCRIPTION

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

C<scalar> exports the nearest C<etc> dir as C<$conf_dir>, or C<''> if
there is none.  The program's config is C<< $conf_dir/<name>.conf >>,
where C<name> is C<basename $0>.

Only the nearest C<etc> dir is used: if it lacks the file the program
dies, even if a farther C<etc> has one.  F<example/find_prog_conf>
uses FindBin::Files to find the nearest C<etc> that has the file.

A test run from F<t/> finds F<t/etc> before the project's F<etc>, so
tests can have their own configuration.

=head1 SEE ALSO

L<FindBin::libs>, F<example/find_prog_conf>,
F<example/multi_config_dir>
