App-cpx
view release on metacpan or search on metacpan
# Try multiple "common" places
# Suboptimal, but we don't have EXE_FILES from EUMM
# nor script_files from MB in CPAN::Meta::Spec
foreach my $dir ("bin", "scripts", "script", ".") {
my $path = "$bin";
if ($dir ne ".") {
$path = "$dir/" . $path
}
$files = $es->search(
index => 'cpan',
type => 'file',
size => 10,
body => {
query => {
filtered => {
query => { match_all => {} },
filter => {
and => [
{ term => { 'path' => "$path"} },
{ term => { 'directory' => \0 } },
{ term => { 'status' => 'latest' } },
]
},
},
},
},
fields => [ 'release', 'author', 'download_url' ],
);
@hits = @{ $files->{hits}->{hits} };
if (scalar @hits > 0) {
print "ð¯ Found [$dir/$bin]\n";
last;
}
}
# We are out of the loop, maybe because we processed all attempts...
if (scalar @hits < 1) {
print "ð Not found\n";
exit -1;
}
# Not exited? Assemble informations for installation
my $to_install = $hits[0]->{fields}->{download_url};
print "ð¦ Release to install [$to_install]\n";
# Install locally with cpm
print "ð§ Will install into $local_lib\n";
my $cpm = App::cpm::CLI->new;
$cpm->run( 'install', "-L$local_lib", $to_install );
# The ultimate goal: execute!
sub execute {
my $ll = shift; # Local Lib
my $b = shift; # bin
if (-f "$ll/bin/$b") {
exec "perl", "-Mlocal::lib=$ll", "$ll/bin/$b", @ARGV;
} else {
print "ð Executable was found, but not installed correctly\n";
exit -1;
}
}
execute($local_lib, $bin);
( run in 4.000 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )