App-Yath-Script
view release on metacpan or search on metacpan
lib/App/Yath/Script.pm view on Meta::CPAN
package App::Yath::Script;
use strict;
use warnings;
use Cwd qw/realpath/;
use Carp qw/confess/;
use File::Spec();
use Importer Importer => 'import';
our @EXPORT_OK = (
qw{
script
module
do_exec
clean_path
find_in_updir
find_rc_updir
mod2file
},
);
our $VERSION = '2.000016';
our ($SCRIPT, $MOD);
sub script { $SCRIPT }
sub module { $MOD }
sub do_begin {
# Check for an explicit version as the very first argument (V# or v#).
# Strip it from @ARGV before anything else sees it.
my $cli_version;
if (@ARGV && $ARGV[0] =~ /^[Vv](\d+)$/) {
$cli_version = int($1);
shift @ARGV;
}
my $argv = [@ARGV];
my @caller = caller();
my $exec = 0;
$SCRIPT = clean_path($caller[1]);
$ENV{YATH_SCRIPT} = $SCRIPT;
inject_includes();
my $local_vers = install_local_lib();
$exec = 1 if find_alt_script();
my ($config, $user_config, $version) = find_rc_files($cli_version);
$version //= $local_vers;
# Pre-parse the global section of the rc files for dev-libs flags
# so a user can put `-D` (etc) at the top of .yath.rc instead of on
# every CLI invocation. Only the global section is parsed -- command
# sections are reserved for the per-command parser since this layer
# has no idea which command is about to run. Run before the regular
# CLI -D pass so `T2_HARNESS_INCLUDES` carries everything across the
# re-exec triggered by either source.
$exec = 1 if parse_rc_dev_libs($config, $user_config);
$exec = 1 if parse_new_dev_libs();
do_exec($argv) if $exec;
$MOD = defined($version) ? load_yath_module($version) : load_latest_yath_module();
$MOD->do_begin(
script => $SCRIPT,
argv => $argv,
config => $config,
user_config => $user_config,
);
}
sub do_runtime { $MOD->do_runtime(@_) }
sub do_exec {
my ($argv) = @_;
$ENV{T2_HARNESS_INCLUDES} = join ';' => @INC;
exec($^X, $SCRIPT, @$argv);
}
sub find_alt_script {
my $script = './scripts/yath';
return 0 unless -f $script;
return 0 unless -x $script;
$script = clean_path($script);
return 0 if $script eq clean_path($SCRIPT);
$SCRIPT = $script;
return 1;
}
sub parse_new_dev_libs {
( run in 1.468 second using v1.01-cache-2.11-cpan-437f7b0c052 )