mascip has asked for the wisdom of the Perl Monks concerning the following question:
Hi there, I wondered if there's any value for such a script, if it's silly, or if there's something better that already exists.
Today I tried using scan-prereqs-cpanfile for the first time, and was disappointed that it didn't detect all of the dependencies of a project. So I had to install quite a few dependencies manually. Hence this little hack to never need to do this again - hopefully.
Warning: this code hasn't been tested at all - I'm at a friend's on Windows, but I really want to get feedback on this idea, and I won't be near my computer for two days. Here is the very simple pseudo code:
### THE SCRIPT:
my $cmd_from_user = join ' ', @ARGV;
while( my $dep = return_a_missing_dependency_for_running($cmd_from_user) ) {
install_a_dependency($dep);
}
### FUNCTIONS:
use Sysadm::Install qw(tap); # tap($cmd): To run a bash command and read the output
sub install_a_dependency {
my $dep = shift;
# TODO: Possibly, prompt me (yes/no) to ask if I want to install $dep by running this command:
my $cmd_to_install_dep = "cpanm $dep"; # Adapt this to your own needs
my ($stdout, $stderr, $exit_code) = tap($cmd_to_install_dep);
die "Could not install module $dep" if could_not_install_dep($stderr); # Some regex in here
}
sub return_a_missing_dependency_for_running {
my $cmd_from_user = shift;
my ($stdout, $stderr, $exit_code) = tap($cmd_from_user);
return extract_missing_dependency_from_output($stderr); # some regex in here. Returns an empty String if no dependencies are missing.
}
This could easily be adapted to any dependency management system. For example for Carton you would do:
# Add the dependency to the cpanfile, and install it with Carton
my $cmd_to_install_dep = $qq{echo "requires '$dep';" >> cpanfile; carton install};
Obviously I'm thinking: if it worked as expected and was useful, it would bloody well exist already. Either I didn't look in the right place, or there is a reason why this is a bad idea.
What do you think?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A hack to automatically install all dependencies for a given script (scandeps)
by Anonymous Monk on Feb 12, 2014 at 00:27 UTC | |
by mascip (Pilgrim) on Feb 12, 2014 at 00:50 UTC | |
|
Re: A hack to automatically install all dependencies for a given script
by Anonymous Monk on Feb 12, 2014 at 02:58 UTC | |
by mascip (Pilgrim) on Feb 12, 2014 at 09:42 UTC |