#!/usr/bin/env perl
########################################################################
# Set PERL5LIB from the lib dirs above this program, then exec the
# program named on the command line with the rest of the arguments.
# See POD.
########################################################################

use v5.40;

use FindBin::libs qw( p5lib nofail );

@ARGV
or die "Usage: $0 program [argument ...]\n";

my $prog    = shift;

# the die reports a failed exec; perl's own warning would repeat it.

no warnings 'exec';

exec { $prog } $prog, @ARGV
or die "Cannot exec '$prog': $!\n";

__END__

=head1 NAME

p5run - run a program with PERL5LIB set from the lib dirs above p5run

=head1 SYNOPSIS

    p5run program [argument ...]

    p5run prove -r t/

=head1 DESCRIPTION

C<p5lib> puts the C<lib> dirs found above C<p5run> at the front of
C<$ENV{ PERL5LIB }>, leaving out any that L<File::Util::SecureDir>
rejects.  C<p5run> then replaces itself with C<program>, which
inherits the environment.  The program can be anything that runs
perl: C<prove>, C<perldoc>, a shell script, or a perl program that
knows nothing about FindBin::libs.

C<program> is found on C<$PATH> unless it contains a C</>.  The
C<exec { $prog } $prog, @ARGV> form never passes the arguments
through a shell.

The dirs are those above C<p5run> itself, not above C<program>:
install it in a project's C<bin> to run anything with that project's
modules.

=head1 SEE ALSO

L<FindBin::libs>
