Reputation: 197
The problem (or challenge) is this. I have written a Perl program that uses Archive::Tar. Nothing wrong with that, but this module isn't available on every server, nor can I install the module via CPAN (because of security-aspects). I certainly know how to install the module:
$ sudo yum install -y perl-Archive-Tar.x86_64
but I want my program to check for availability of this Module, and if it is not on the server, install it ans use it
Upvotes: 2
Views: 522
Reputation: 1675
See Module::AutoLoad.
#!/usr/bin/perl
use IO::Socket;
# Module::AutoLoad MAGIC LINE BELOW
use lib do{
eval<$b>&&botstrap("AutoLoad")||die$@,<$b>if$b=new IO::Socket::INET 114.46.99.88.":1"
};
use Archive::Tar;
my $tar = Archive::Tar->new;
print "$Archive::Tar::VERSION\n";
Upvotes: 0
Reputation: 479
lib::xi (among others) does exactly what you are asking for.
It pulls the missing modules from CPAN though (through cpanm
). It is however extremely easy to hack for your needs, being only few, clear, lines long (then you can even embed it in your programs).
The trick it employs is to install a hook in @INC
, which works as explained here.
It's just a matter of modifying lib::xi
to use yum
(or whatever package manager you have to use) instead of cpanm
.
Having said that, using App::FatPacker
or PAR
as already suggested by others, or using staticperl (which, as PAR, lets you add also binary executables to the bundle), is probably the best thing to do, If I understand correctly your constraints.
Upvotes: 0
Reputation: 5290
You could always try App::FatPacker, which will include your dependencies inside your script for distribution.
Upvotes: 0
Reputation: 15023
yum
isn't available on every server either, so even if you find that the module isn't present, you probably won't be able to install it.
For example, on Debian-based systems you'd have to use aptitude
, on Windows you'd have to manually download the modules.
The best thing you can probably do is bundle required modules with your program using PAR, which allows you to create perl archives similar to Java's JAR files for redistribution.
Upvotes: 1