http://qs321.pair.com?node_id=854000

baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:

hi,

well here is the problem. let say i would like to install some module : A.pm

And this module depends on 10 different modules , and some of those modules depend on several other modules ... you get the picture.

to install everything what i would do is, i would use cpan and run the instalation of module A.pm and cpan would ask me do i want to install all the dependencies and i would say yes. ok. so my question is how would i do this automatically, so when i set my perl program on my machine and start it for the first time, then i would like that my program identifies all required modules and if they do not exist ask the user would he or she would like to install them .

BEGIN { my @modules; eval{"use Data::Dumper;"}; push(@modules,"Data::Dumper") if $@; eval{"use Getopt::Long;"}; push(@modules,"Getopt::Long") if $@; eval{"use Term::ReadLine;"}; push(@modules,"Term::ReadLine") if $@; eval{"use Term::ReadKey;"}; push(@modules,"Term::ReadKey") if $@; eval{"use File::Copy;"}; push(@modules,"File::Copy") if $@; eval{"use File::Path;"}; push(@modules,"File::Path") if $@; eval{"use Cwd;"}; push(@modules,"Cwd") if $@; eval{"use IO::Socket;"}; push(@modules,"IO::Socket") if $@; eval{"use bignum;"}; push(@modules,"IO::Socket") if $@; eval{"use Term::ANSIColor;"}; push(@modules,"Term::ANSIColor") if $@; die "Some modules are missing, please install the following modules + and try again:\n -- " . join("\n -- ",@modules) if @modules; }
when the user says YES then connect to the net and identify all dependencies of all modules and download and install everything.

The reason im avoiding cpan interface is because i received some complaints that cpan is too hard to install and that it asks too many questions that a regular MSOffice user doesn't understand. so what i would like to do is to make a script that would identify all necessary dependencies and the when user says 'yes' to install them locally in some folder from where my program knows to read them. without any knowlage what is happening behind the curtains

use lib "./Lib";
are there any examples, or did anyone already done something in this area so i don't reinvent the circular thing on the car or bike or ....

thnx

Replies are listed 'Best First'.
Re: installing modules
by Corion (Patriarch) on Aug 10, 2010 at 11:09 UTC

    There is App::FatPacker to collect all prerequisites and paste them into your main script. Also, PAR::Packer collects the prerequisites somehow.

    I guess the most common approach is to run your program and at the program exit, dump %INC, which contains all loaded modules:

    use Data::Dumper; END { print Dumper \%INC; };
Re: installing modules
by marto (Cardinal) on Aug 10, 2010 at 11:10 UTC